PHP - Mysql_fetch_array In A While Loop Not Working
Hello all,
I am having trouble with a piece of code. I have used the same piece of code on a different server and I had no problems. Suddenly I do. - I use this code to load info into a Flash website to browse through all rows in a table; - Inside the table currently there is one record; - NumLow is being passed through the url; - echo "&aantalEvenementen=".$aantalEvenementen; shows 1 record just fine; - the record doesn't get printed though... the error is somewhere in the while loop. Hope someone can point me in the right direction! Cheers, Code: [Select] // Connect to mySQL Server $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error bij het verbinden met de MYSQL server: " . mysql_error()); // Select mySQL Database mysql_select_db($DBName, $DBConn) or die("Error bij het verbinden met de MYSQL database: " . mysql_error()); //amount of rows that are shown at once $numComments = 1; //select the right table $sql = "SELECT * FROM $table"; //loading events $nieuweEvenementen = mysql_query($sql, $DBConn) or die("Error bij het ophalen van de concerten: " . mysql_error()); //amount of rows $aantalEvenementen = mysql_num_rows($nieuweEvenementen); //order rows $sql .= ' ORDER BY `concertDatum` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments; //loaded row $geladenEvenement = mysql_query($sql, $DBConn) or die("Error bij het laden van het concert: " . mysql_error()); //echo amount of rows echo "&aantalEvenementen=".$aantalEvenementen; //if no records, display message, otherwise print row if($aantalEvenementen == 0) { echo "&concertOmschrijving=Er zijn geen concerten. U kunt nieuwe concerten aanmaken via de concertenkalender."; } else { while ($array = mysql_fetch_array($geladenEvenement)) { $concertNaam = mysql_result($geladenEvenement, $i, 'concertNaam'); $concertArtiest = mysql_result($geladenEvenement, $i, 'concertArtiest'); $concertDatum = mysql_result($geladenEvenement, $i, 'concertDatum'); $concertTijd = mysql_result($geladenEvenement, $i, 'concertTijd'); $concertOpen = mysql_result($geladenEvenement, $i, 'concertOpen'); $concertOmschrijving = mysql_result($geladenEvenement, $i, 'concertOmschrijving'); echo "&concertNaam=".$concertNaam; echo "&concertArtiest=".$concertArtiest; echo "&concertDatum=".$concertDatum; echo "&concertTijd=".$concertTijd; echo "&concertOpen=".$concertOpen; echo "&concertOmschrijving=".$concertOmschrijving; $i++; } } // if there are no more records (all are loaded), show message if($_GET['NumLow'] > $aantalEvenementen) { echo "$eventOmschrijving=Alle concerten zijn reeds geladen."; } } Similar TutorialsThis is a pain. It seems totally logical to me and I had it working before I accidentally saved over the working version (major boo boo). This is two code snippets, first one is how I want it to work - One Query and the loop through results. Second does work, but then its going to have to run mysql 60 times, which could get slow as the site gets more use. $results = mysql_query($query); $response .= "<table><tr>"; if($nit == 0){ for($i = 0; $i < 60; $i++){ $dateCompare = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+$i,date("Y"))); $dateForString = date("D d/m/Y", mktime(0,0,0,date("m"),date("d")+$i,date("Y"))); $response .= "<td height='350px' style='color:white; background-color:grey;'>$dateForString</td>"; while($row = mysql_fetch_array($results)){ $id = $row['id']; $poster = $row['poster']; $date = $row['date']; $response .= "$date : $dateCompare<br>"; if($date == $dateCompare){ $response .= "<td><a href='fullinfo.php?selected_id=$id'><img src='$poster' height='350px' /></a></td>"; } } } } FOLLOWED BY THE SECOND $response .= "<table><tr>"; if($nit == 0){ for($i = 0; $i < 60; $i++){ $dateCompare = date("Y-m-d", mktime(0,0,0,date("m"),date("d")+$i,date("Y"))); $dateForString = date("D d/m/Y", mktime(0,0,0,date("m"),date("d")+$i,date("Y"))); $response .= "<td height='350px' style='color:white; background-color:grey;'>$dateForString</td>"; $results = mysql_query($query); while($row = mysql_fetch_array($results)){ $id = $row['id']; $poster = $row['poster']; $date = $row['date']; if($date == $dateCompare){ $response .= "<td><a href='fullinfo.php?selected_id=$id'><img src='$poster' height='350px' /></a></td>"; } } } } First one results in -it seems - to only go through the while loop once, the first time. So out put is todays date, for the number of results from the database. The second works fine, prints out in order and matches up. I just don't like its inefficiency. Thanks Canty why it giving me single row data?? what i m missing here ... any help wil b appreciated.. <?php$comments= "";$result = mysql_query("SELECT * FROM comment");while($row = mysql_fetch_array($result)) { $serials= $row['serial']; $names= $row['name']; $emails= $row['email']; $msges= $row['msg']; $date_added= $row['date']; $comments= "$names <br /> $msges <br /> $date_added"; } ?>() Currently I have 5 entries in my table. Entring this query displays all five in the correct order. Code: [Select] SELECT * FROM products ORDER BY count DESC LIMIT 16 However, using this code, the first result is omitted and the last four are displayed. $query="SELECT * FROM products ORDER BY count DESC LIMIT 16"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<div>'; while ($row = mysql_fetch_array($result)) { echo '<div>'.$row[product].'</div> <div>'.$row[count].'</div>'; } echo '</div>'; Can someone help me find my error? Thanks greetings! I have here codes that have two checkboxes, if 1 checkbox is checked, the other and textbox is disabled. I think my codes in js is functional, my problem is how to put it inside the mysql_fetch_array, I want to put those checkbox in every data fetch from my db. only the first data is affected ..i really appreciate your help guys! <?php include('connect-db.php');?> <html> <head> <script language = "Javascript" type="text/javascript" > function checkbox_disabled(tocheck,todisable,todisable2) { var x = document.getElementById(tocheck); if(x.checked){ document.getElementById(todisable).disabled=true; document.getElementById(todisable2).disabled=true; document.getElementById(todisable2).checked = false; }else{ document.getElementById(todisable).disabled=false; document.getElementById(todisable2).disabled=false; document.getElementById(todisable2).checked = true; } } </script> </head> <body> <?php echo "<table>"; $query = mysql_query("SELECT * FROM tbl_user") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'.$row['user_Id'].'</td>'; echo '<td>'. $row['user_Fname'].'</td>'; echo '<td>'.$row['user_Lname'].'</td>'; echo "<td><input type='checkbox' id='checkbox1' value ='checked' onclick=checkbox_disabled('checkbox1','textbox1','checkbox2')></td>"; echo '<td><input type="checkbox" id = "checkbox2"><input type="text" id="textbox1" /><td>'; echo '</tr>'; } echo "</table>"; ?> </body> </html> I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. Hello everyone! I am trying to pull from mysql a row of first names in a while loop but I keep getting the error message Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in line 52 The code is; <?php $first_name = $_POST['firstname']; $last_name = $_POST['lastname']; $full_name = $_POST['firstname'] . ' ' . $_POST['lastname']; require_once ('swdb_connect.php'); $query = "INSERT INTO description(firstname, lastname) VALUES ('$first_name', '$last_name')"; $result = @mysql_query ($query); while($row = mysqli_fetch_array($result)) { echo $row['firstame'] . '<br />'; ?> I don't understand why I get the error message, I have over 20 names in mysql If anyone can help that would be great It's only displaying the first result and not the others. What am I doing wrong? I'm selecting the items the user occupies. Then I'm selecting the name and image of that item from the item table. Code: [Select] echo "<table cellspacing=\"0\" class=\"news\" align=\"center\">"; echo "<tr>"; $sql = "SELECT * FROM useritems WHERE userid='".$_SESSION['userid']."' LIMIT $offset, $rowsperpage"; //selects all the users items to whoever is logged in $result = mysqli_query($cxn,$sql) or die(mysqli_erro($cxn)); $imagecount = 0; while ($row = mysqli_fetch_assoc($result)) //while there are still results { extract($row); $quantity = $row['quantity']; $itemid = $row['itemid']; $sql = "SELECT * FROM items WHERE itemid='".$itemid."'"; //selecting the name and image of the item that is displaying $result = mysqli_query($cxn, $sql) or die(mysqli_error($cxn)); $row = mysqli_fetch_assoc($result); $name = $row['name']; $image = $row['image']; if ($imagecount%5 == 0) //after 5 items have been listed, start a new line { echo "</tr>"; echo "<tr>"; } } echo "<td width=\"120px\" align=\"center\">"; echo "<img src=\"http://www.elvonica.com/".$image."\"><br>"; echo $name." (".$quantity.")"; echo "</td>"; $imagecount++; //after one item has been displayed, redo the loop if there are still results } echo "</table>"; Can anyone help me with why this code would only send 1 email when the query returns 8 rows?
I am pretty sure it will be simple but I can't find the problem!
$sql = "SELECT email, supplier_id FROM tbl_suppliers"; $stmt = $db->prepare($sql); $stmt->execute(); foreach($db->query($sql) as $row){ $supp_id = $row['supplier_id']; $emailCSV->setEmailMessage("some generic text message"); $email = $row['email']; $emailCSV->sendEmail("me@me.com",$email,"Quote Request"); } Okay I am trying to do a for loop within a while loop and its so far not working. Here is what I currently have. It echo's nothing out. Also If I remove the Code that generates information from the for loop It echo's out perfectly so It has something to do with the for loop. PHP Code so Far: Code: [Select] <?php if(isset($_POST['system'])){ $system = $_GET['system']; }else{ $system = 1; } $q = "SELECT * FROM `planets` WHERE `system` = '$system' ORDER BY `id` ASC LIMIT 9"; $res = mysql_query($q) or die("Error:<br />".mysql_error()); $couny = mysql_num_rows($res); while($row = mysql_fetch_array($res)){ for($i=1; $i>=$couny; $i++){ ?> <li> <span <?php if($i=1){echo "id='mercury'";} if($i=2){echo "id='venus'";} else if($i=3){echo "id='earth'";} else if($i=4){echo "id='mars'";} else if($i=5){echo "id='jupiter'";} else if($i=6){echo "id='saturn'";} else if($i=7){echo "id='uranus'";} else if($i=8){echo "id='neptune'";} else if($i=9){echo "id='pluto'";}?>id="mercury"><?php echo $row['name']; ?></span> <p><?php if($colony['building11'] >= $row['building11']){?> This Colony Currently Has the Following:<br /> Hydrogen: <?php echo num($row['recource1']); ?><br /> Gold: <?php echo num($row['recource1']); ?><br /> Platinum: <?php echo num($row['recource1']); ?><br /> Silver: <?php echo num($row['recource1']); ?><br /> Bio-Waiste: <?php echo num($row['recource1']); ?><br /> Plasma: <?php echo num($row['recource1']); ?><br /> Metal: <?php echo num($row['recource1']); ?><br /> <?php }else{?> <font color="red">Insufficiant Observatory Level!</font><br /> Hydrogen: ???????????????<br /> Gold: ???????????????<br /> Platinum: ???????????????<br /> Silver: ???????????????<br /> Bio-Waiste: ???????????????<br /> Plasma: ???????????????<br /> Metal: ???????????????<br /> <?php } ?></p> </li> <?php } } ?> Thanks Brian. PS. The Attached Image is what it looks on my end the for and while loops displays the planets in the system right under the red Solar System Star Text. Thank you again for any help. This is a code pinch from a webpage of my project. Here I want to display user selected categories and then want to display its subjects that belong to category. There, users could have more than 1 category and It no problem I can print all those category in my first while loop... but problem is when Im try to print subjects it has only one row as a result.. there are more subjects in each category. can anybody tell me what has happens? this is my code.... Note: both queries are working properly.. I tried those user mysql client program. Code: [Select] <?php require_once ('../../includes/config.inc.php'); require_once( MYSQL1 ); $q = "SELECT institute_category.category_id, category_name FROM institute_category INNER JOIN category ON institute_category.category_id = category.category_id WHERE institute_category.institute_id = $instituteId"; $r = mysqli_query( $dbc, $q); while ( $row = mysqli_fetch_array ( $r, MYSQLI_ASSOC) ) { $categoryId = $row['category_id']; $category = $row['category_name']; echo '<fieldset class="alt"> <legend><span>Category : <em style="color: red;">' . $category . '</em></span></legend>'; $qy = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = $categoryId"; $result = mysqli_query( $dbc, $qy); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($row = mysqli_fetch_array( $result, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="subject[]" value="' . $row['category_id'] . ":" . $category . ":" . $row['subject_id'] . ":". $row['subjects'] . '" /> ' . $row['subjects'] . '</td>' . "\n"; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } echo '</fieldset>'; ?> any comments are greatly appreciated.. thank you I'm trying to create a part of a script where by the system will generate a sku code and loop through out to see if this exists in the database, if the sku does the script adds one too the code so 001 will turn to 002 then it will keep looping until it finds a SKU that isn't in the database.
However I can get the script to keep generating the new SKU codes but it will only test the first SKU code so the loop will keep going if it exists.
$number=001; if(isset($_POST['submit'])){ $product = $_POST['product']; $brand = $_POST['brand']; $description = $_POST['description']; $contruct=strtoupper($product."-".$brand."-".$description); $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; $query=$cc_db->query("SELECT `sku` FROM `product` WHERE `sku`='".$check_for."'"); $fetch=$cc_db->fetch_object($query); $checking=$cc_db->num_rows($query); while($checking > 0){ echo"$check_for is there : $checking rows : $fetch->sku<br>"; $number=$number+1; $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; } echo $checking; echo $check_for; } I have never used cURL before but I need to use it for developing a facebook application. What I am trying to do is create a status update scheduler. There are two tables in my database. One table has generic updates for each day of the week an the other had special events. My script checks the day, checks to see if there is a special event in the future on that day, and if there is reminds guests of the upcoming event. If there is no event it posts the generic status. Code: [Select] <?php include('config.php'); $result2 = mysql_query("select facebook_id,facebook_access_token from admin where username='users'"); $row = mysql_fetch_array($result2); $facebook_id = $row['facebook_id']; $facebook_access_token = $row['facebook_access_token']; $day = date('N'); $result2 = mysql_query("select * from events where date > CURDATE() order by date ASC") or die(mysql_error()); $num_rows = mysql_num_rows($result2); if($num_rows == 0) { $result2 = mysql_query("select * FROM alerts WHERE id='$day'") or die(mysql_error()); $row1 = mysql_fetch_array($result2); echo 'There are no events just alerts'; } else { while($row = mysql_fetch_array($result2)){ if(date('N',strtotime($row[date])) == $day) { $id = $row['id']; $result1 = mysql_query("SELECT * FROM events WHERE id = $id") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } else { $result1 = mysql_query("SELECT * FROM alerts WHERE id = $day") or die(mysql_error()); $row1 = mysql_fetch_array($result1); } } } $params = array('access_token' => $facebook_access_token, 'message' => $row1[alert_message], 'name'=> $row1[alert_name], 'caption' => $row1[alert_caption], 'link' => $row1[alert_link], 'description' => $row1[alert_description], 'picture' => $row1[alert_picture] ); $url = "https://graph.facebook.com/$facebook_id/feed"; $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => $url, CURLOPT_POSTFIELDS => $params, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => true )); $result = curl_exec($ch); ?> The problem seems to be occurring when the While loop is accessed. I have used 'echo' to follow the variables through the script and it all seems to be working. However if I try and execute the cURL and the While Loop has run then it does not seem to work. I know the cURL part works becuase if the variables cause the first IF statement default to ELSE then it runs fine. Any help would be GREATLY appreciated. hello.. In this script. if part is working properly. but elseif part not working i expect. it display only 1 category and its subjects. Anybody can tell me what the mistake that I have did... Here is my script Code: [Select] } elseif ( isset($_POST['category']) && ( sizeof( $_POST['category']) == 2 || sizeof( $_POST['category']) == 3 )) { $q = 'SELECT * FROM category ORDER BY category_id'; $r = mysqli_query( $dbc, $q); while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )) { foreach( $category as $value ) { if ( $value == $row['category_id']) { echo '<input type="radio" name="category[]" value="' . $row['category_id'] . '" class="radio" />'; echo '<label for="" class="radio"> ' . $row['category_name'] . ' <strong>: Mark this category as my "Main Category"</strong></label><br />'; $q = "SELECT category_subject.category_id, category_subject.subject_id, subjects FROM category_subject INNER JOIN category ON category_subject.category_id = category.category_id INNER JOIN subject ON category_subject.subject_id = subject.subject_id WHERE category_subject.category_id = {$row['category_id']}"; $r = mysqli_query( $dbc, $q); $c = $i = 0; echo '<table class="form_table" ><tr>'; while($info = mysqli_fetch_array( $r, MYSQLI_ASSOC )){ // if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row: if( ($c % 2) == 0 && $c != 0){ echo "</tr><tr>"; } echo '<td width="50%"><input type="checkbox" name="category[]" value="' . $info['subject_id'] . '" /> ' . $info['subjects'] . '</td>'; $c++; } // while.. // in case you need to fill a last empty cell: if ( ( $i % 2 ) != 0 ){ // str_repeat() will be handy when you want more than 2 columns echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) ); } echo "</tr></table>"; } } } } I am trying to delete records across 3 tables but my code does not work. Code: [Select] $query = ("SELECT `propertyref` FROM `feed_property` WHERE `status` = 'Sold' ")or die(mysql_error()); $result = mysql_query($query); if (isset($result)) { while ($row = mysql_fetch_array($result)): $ref1 = mysql_real_escape_string($row['propertyref']); $query1 = ("DELETE FROM `feed_property`, `feed_images`, `feed_characteristics`\n" . "USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics`\n" . "WHERE feed_property.propertyref = '$ref1'\n" . " AND feed_images.propertyref = feed_property.propertyref\n" . " AND feed_characteristics.propertyref = feed_property.propertyref; ")or die(mysql_error()); echo $query1; endwhile; if(!mysql_query($query1)){ echo '<h1 style="color: red;">Error</h1><p>', mysql_error(), '</p>'; } else { echo '<h1 style="color: red;">Properties have been removed from the database</h1>'; } } Query1 echos as: Code: [Select] DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc1' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; DELETE FROM `feed_property`, `feed_images`, `feed_characteristics` USING `feed_property` INNER JOIN `feed_images` INNER JOIN `feed_characteristics` WHERE feed_property.propertyref = 'abc2' AND feed_images.propertyref = feed_property.propertyref AND feed_characteristics.propertyref = feed_property.propertyref; The query completes without errors but does not delete the entries in the DB. If I run the query singly in PHP My Admin it functions correctly. thanks for your help I have a while loop nested inside of another while loop to populate a drop-down select box for each result from the parent while loop. The inner loop only gets run once though... any ideas on how to fix this without it being extremely data heavy? I have the following form the just has one field. Code: [Select] <html> <head> <title>Post</title> </head> <body> <form action="worldpay_callback.php" method="post"> <input type="text" name="username" id="username" /> <input type="submit" name="submit" id="submit" value="send" /> </form> </body> </html> I am then posting the form to the following page that is meant to loop through all of the post values and save them to a text file. For some reason my foreach loop doesn't seem to be working as done of the post values are getting written to the text file. Can anyone see anything I'm doing wrong? Code: [Select] $myFile ="notifications.txt"; $fh = fopen($myFile, 'w+') or die("can't open file"); foreach($_POST as $k=>$v) { $data = 'POST: Key:'.$k.' - Value:'.$v ." \n"; fwrite($fh, $data); } fclose($fh); return "[OK]"; Thanks for any help I am a noob at php, looking to become great. My php loop only seems to draw 1 row from the database when listing it out. Here is the loop <?php require('header.php'); mysql_select_db('center'); $sql = "select username, password from users"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $user = $row['username']; $pass = $row['password']; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>$user</td>"; echo "<td>$pass</td>"; echo "</tr>"; } echo "</table>"; ?> Hi brains... I must be missing some core concept here that I hope someone can set me straight on.. I have a database query that returns say 8 rows. Here's how I know... $link6_result10 = mysql_query($link6_sql10) or die("Link6 SQL10 Failed: Function drawInventory: " . mysql_error()); $link6_rows10 = mysql_num_rows($link6_result10); $link6_array10 = mysql_fetch_array($link6_result10, MYSQLI_ASSOC); echo "You have $link6_rows10 items in your inventory."; <<---- returns 8 So why in the world does this not work??? What is the flaw in my logic? $srchStr = null; foreach ($link6_array10 as $sn) { $srchStr .= " SerialNumber = '$sn' OR"; echo "SN is $sn "; } The only echo output of the foreach function is "SN is 12345" Not the 8 rows of content that I would expect. isn't this how foreach loops should work? Why do I not see "SN is 12345 SN is 23456 SN is 34567 etc..."????? I'm confused. Thanks guys for any help. Hi guys Probably a simple but trying to figure out why I cant get this while loop to work (at least I think its the loop) Query works as it returns 1 row, but not all of them. Any help would be great! $sql = "SELECT * FROM requests ORDER BY leave_after DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo '<div id="resultholder">'; echo "<p>Request ID:" . $row['id'] . ", User ID: " . $row['user_id'] . ", Departing From: " . $row['departing'] . ", Going To: " . $row['destination'] . " , Leaving After: " . $row['leave_after'] . " , but Arriving Befo " . $row['arrive_before'] ."</p></div>"; echo '</div>'; } } } Thanks! |