PHP - Php Alternate Row Help Please
Hi guys i need a little help to list data in different coloured rows
i need to list 1st name in <td class="alt1"> 2nd name in <td class="alt2"> and so on currently it is listing only in <td class="alt1"> here is my code any help really appreciated [php]<?php $result[0] = mysql_query("SELECT * FROM videos ORDER BY viewtoday DESC LIMIT 10"); for($i=0;$i<count($result);$i++) { echo ''; while($row=mysql_fetch_array($result[$i])) { $id = $row['id']; $cat = $row['cat']; $title = $row['title']; $numviews = $row['viewtoday']; $max_length = 25; $title = ( strlen($title) > $max_length ? substr($title,0,$max_length)."..." : $title ); echo '<table class="listOfShows listOfShowsFirst"><tr> <td class="alt1"> <a href="videos.php?id=' . $id . '">'. $title . '</a> </td> </tr>'; } } ?> </table></td></table>/php] Similar TutorialsI've been using php's strstr() function to find data before an @ character in a string. Work fine for my local ide. I just uploaded all my files to a host to start debugging emails and it came to my attention that my hosting environment is running version 5.2.9 and strstr() isn't fully supported. Heres a bit of code from the manual to show i'm talking about Code: [Select] <?php $email = 'name@example.com'; $domain = strstr($email, '@'); echo $domain; // prints @example.com $user = strstr($email, '@', true); // As of PHP 5.3.0 <-- echo $user; // prints name ?> I can't use the third argument apparently. Is there another way to go about doing this? Hi all, i want delete old updated images with considering its index in array. <?php global $oldimg; $oldimg = array(); //action: edit news if (isset($_GET['id'])) { $NewsID = (int)$_GET['id']; if ($NewsID == 0) { $rdir = '<META HTTP-EQUIV="Refresh" CONTENT="1.4;URL=panel-news.php">'; die($rdir);} //get user from the database and put data into $_POST variables. //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $rs = mysql_query("SELECT newsimg1, newsimg2, ". " newsimg3 FROM news WHERE id = $NewsID"); if (mysql_num_rows($rs) == 0) die('no such a newsID!'); $row = mysql_fetch_assoc($rs); $oldimg[0] = $row['newsimg1']; $oldimg[1] = $row['newsimg2']; $oldimg[2] = $row['newsimg3']; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> <input type="hidden" name="NewsID" value='<?php echo (isset($NewsID))?$NewsID:"0";?>'> <input type="submit" value="edit" id="save" name="save"/> </form> <?php if (isset($_POST['save']) && isset($_POST['NewsID'])){ $NewsID = (int)$_POST['NewsID']; //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //max fle size value $max_file_size = 2097152; //Global newsimg global $newsimg;global $ctr; $ctr = 0; //timestamp to make files unique names $timestamp = time(); //destination folder path $destpath = "../Dir/Newsimg/"; //looping each file or image from the form while(list($key,$value) = @each($_FILES["file"]["name"])) { //check if any empty or errors if(!empty($value)){ if ($_FILES["file"]["error"][$key] > 0) { $edir ='<div id="fail" class="info_div">'; $edir .='<span class="ico_cancel"><strong>'; $edir .="err : ". $_FILES["file"]["error"][$key] .'</strong></span></div>'; echo($edir); } else { //add the timestamp to filename $file_name = $timestamp.$_FILES['file']['name']; //temp name from upload form, key of each is set $source = $_FILES["file"]["tmp_name"][$key] ; //getting the file type $file_type = $_FILES["file"]["type"][$key]; //placing each file name into a variable $filename1 = $_FILES["file"]["name"][$key]; //lowering the file names $filename = strtolower($filename1); //adding timestamp to front of file name $filename = "$timestamp$filename"; ++$timestamp; if ($file_type != "image/jpeg" && $file_type != "image/png" && $file_type != "image/jpg") { die(" <div id='fail' class='info_div'> <span class='ico_cancel'><strong> Invalid Format!</strong></span><br /> <a href=\"javascript: history.go(-1)\">Retry</a> </div>"); } //moving the file to be saved from the temp location to the destination path move_uploaded_file($source, $destpath . $filename); //the actual final location with timestamped name $final_file_location = "$destpath$filename"; if (file_exists($final_file_location)) { if (isset($oldimg[$ctr])) { chdir('../Dir/Newsimg/'); echo $oldimg[$ctr]; unlink($oldimg[$ctr]);} $newsimg[$ctr] = $filename; $ctr++; ?>TNX. Hi, I'm using a table to list results from a MySQL query. I wanted to make the rows of the table alternate colours and found the following code on this website which does the job perfectly: $counter++; $bgcolor = ($counter % 2)?"#e8edff":"#ffffff"; echo "<tr class='border'>\n <td bgcolor='".$bgcolor."'>$n</td>\n <td bgcolor='".$bgcolor."'>$player</td>\n <td bgcolor='".$bgcolor."'>$score</td>\n </tr>\n"; On my webpage i have six tables listing results from six MySQL queries and i use the above code after each query to construct the table and alternately colour the rows blue then white. My problem arises when there are an odd number of rows in the first table. This results in the first row of the second table being coloured white, not blue. I would like the first row of each table to be blue. Is there a simple way to reset the counter for each table? Any advice much appreciated. Thanks. Hi guys, I would like to know on How to alternate table row colors in Php Mysql result? CSS or Html? Thanks Code: [Select] <? $result = mysql_query("SELECT * FROM tbl_sta WHERE fiesta_date > '$now' ORDER BY sta_date LIMIT 5"); echo "<table id='table1' cellspacing='1' cellpadding='3'> <tr> <th>Upcoming Fiesta</th> </tr>"; while($row = mysql_fetch_array($result)){ $date = date("l, F j ",strtotime($row["sta_date"])); echo "<tr>"; echo "<td><a href='fiestasd.php' style='font-size:12px;font-weight:bold;'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> <br /> $date </td>"; echo "</tr>"; } echo "</table>"; ?> Thank you.. more power phpfreaks! Without using FFMPEG that is, since my host refuses to allow it. I really don't want to change hosts just for this one thing, I'm happy otherwise, but I need this work. I just need to grab a frame from a video when the user uploads the video. I can't use FFMPEG like I said, but I saw a suggestion someone had that said "have PHP open the video in fullscreen and take a screencap". That would work perfectly, I just have not a CLUE how to do it. Does anyone have experience doing this? I just want it to grab a screenshot and have it saved as a jpg with the same filename as the video, for obvious reasons...call the video player and pass it the filename with a .jpg attached for the screenshot param. Any help is appreciated! Thanks. Hi all, I am still learning all the variations of code commonly used with sites. I have one particular issue of which I am having trouble locating an answer or returning a proper result. I want to be able to use one page to query a distinct date, say 1-1-11 and the results return with the other columns matching this date and separating the time to be displayed for the entry row. So it would look something like this in the results. Acct: Tester User: John.Smith Time: 1:30 PM Currently there are 4 columns to the table, ID, Acct, Logintime, User. I have tried splitting this off the table but that fails out, unless someone knows an insert command to enter date and time individually. This would make it much easier for my purposes as well. Below is one of the many codes I have tried for this from examples. <?php $con = mysql_connect("localhost","gram","compassion"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("tester", $con); $result = mysql_query("SELECT * FROM test_history"); echo "<table border='1'> <tr> <th>Date:</th> <th>Time:</th> </tr>"; while($row = mysql_fetch_array($result)) (explode(" ",$row['logintime'])); echo $row[0]; echo $row[1]; { echo "<tr>"; echo "<td>" . $row[0] . "</td>"; echo "<td>" . $row[1] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I know I am newb but I am a fast learner if I can merely get some points in the right direction. Hi There! Hopefully someone can help. I'm looking for some php script that allows me to display mysql table data in alternating row colors (eg 5 columns and 500 rows). I would also like to add pagination and limit number of rows displayed at a time to e.g. 50. If possible I'd like to be able to sort asc/desc using titles(links) at the top of the displayed data. Hopefully someone may have a script like this that also shows the mysql connection code (sample host, pass, user etc...) - a working php file so to speak that I can edit. Would really appreciate the help. If you could recommend some software or a wizard that could generate the php code for me I would really appreciate it too! THANKS! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=305845.0 Can anyone provide a snip of code that I could insert into the "coupon code" field on a formmail form which has the following effect: on submit form, user goes to the normal payment page (this is already implemented) if coupon code field is filled out with correct code, user is taken to alternate payment page on form submit. Either this or another approach which has the same result is OK. I am a novice coder working in a wysiwyg - I don't REALLY know php at all - I just need a snip I can insert and a clear instruction. Thanks so much for any help. |