PHP - Saving The Result Of A While Loop As A Variable
I want to save the results of a loop as a variable ie $output. I have tried encasing the php within quotes but it does not work. Is there a way to save the complete results as a variable?
$result = mysql_query("SELECT * FROM $table2 WHERE $db_item_1 OR $db_item_2", $connection); if (!mysql_num_rows($result)) { echo "Error 13424 - not working"; exit(); } while ($row = mysql_fetch_array($result)) { echo "<tr><td scope=\"col\" style=\"font-size: 16px; color: #333333; padding: 10px 8px; border-bottom: 1px solid #919191;\"><div align=\"left\" style=\"font-size: 20px;\">" . $row['date'] . "</div></td> <td scope=\"col\" style=\"font-size: 16px; color: #333333; padding: 10px 8px; border-bottom: 1px solid #919191;\"><div align=\"left\"></div></td> <td scope=\"col\" style=\"font-size: 16px; color: #333333; padding: 10px 8px; border-bottom: 1px solid #919191;\"><div align=\"left\" style=\"font-size: 20px;\">" . $row['title'] . "</div></td> <td scope=\"col\" style=\"font-size: 16px; color: #333333; padding: 10px 8px; border-bottom: 1px solid #919191;\"><div align=\"left\"></div></td> <td scope=\"col\" style=\"font-size: 16px; color: #333333; padding: 10px 8px; border-bottom: 1px solid #919191;\"><div align=\"left\" style=\"font-size: 20px;\">" . $row['cost'] . "</div></td> </tr>"; }echo $complete;() The part I want as one result (ie. $complete) is the result of the while loop. There is always at least one result but sometimes 10 which means that it creates 10 table rows. I need to do it this way as later on in the page I use a pdf converter which does not allow loop checks within it otherwise I would just place it within the converter. Similar TutorialsHi.. I need to save data from a while loop and data from select option, Now I encountered that using my query I only save is the last part of my while loop and also the data that I choose in select option did not save. here is my code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items = $_POST['Items']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty', UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy', ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'"; $result = mysql_query($sql, $con); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <style type="text/css"> #ddcolortabs{ margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs a span{ float:none; } #ddcolortabs a:hover{ background-color: #678b3f; } #ddcolortabs a:hover span{ background-color: #678b3f ; } #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style type="text/css"> #ddcolortabs1{ position: relative; top: 10px; margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs1 ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs1 li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs1 a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs1 a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs1 a span{ float:none; } #ddcolortabs1 a:hover{ background-color: #678b3f; } #ddcolortabs1 a:hover span{ background-color: #678b3f ; } #ddcolortabs1 #current a, #ddcolortabs1 #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #SR_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 270px; width: auto; height: auto; float: left; top : 10px; } table { margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: .9em; border: 1px solid #DDD; width: auto; } th { font-family: Arial, Helvetica, sans-serif; font-size: .7em; background: #694; color: #FFF; padding: 2px 6px; border-collapse: separate; border: 1px solid #000; } td { font-family: Arial, Helvetica, sans-serif; font-size: .7em; border: 1px solid #DDD; text-align: left; } #RequestedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #ApprovedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #ReceivedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #IssuedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; margin-right: 120px; } #save_btn{ position: relative;; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; top: 10px; } </style> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items = document.getElementById("Items").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<tr> <td style='border: none;'> </td> <td style='border: none;'> <input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <div id='RequestedBy'> <label>Requested By:</label> <select name="Requested_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ApprovedBy'> <label>Approved By:</label> <select name="Approved_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ReceivedBy'> <label>Received By:</label> <select name="Received_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id='IssuedBy'> <label>Issued By:</label> <select name="Issued BY"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onclick="save_sr()"> </div> </body> </html> I also I attach the display data. Thank you I am trying to save LAST_INSERT_ID() to a session variable for later use but not with much success. This doesn't work. $_SESSION['lastid'] = LAST_INSERT_ID(); Thank you! I have a Google Adsense code that I am saving to the wp_options table. I can successfully save and retrieve the variable containing the google adsense code but it doesn't do anything except display it as plain text on screen. Hi, I would like to ask, how to display the while loop result 3 per row with the following code below: $startDate = strtotime($datefrom); I am having a little bit of trouble with this piece of code. I'm sure it's something simple, but I have been working on this thing all day and want to get it finally finished. Here's the troublesome code: function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } $sql_clean = "SELECT * complete WHERE createdate < date_sub(current_date, interval 1 minute)"; $sql_list = mysql_query($sql_clean); while($row = mysql_fetch_assoc($sql_list)) { $directory = "complete/" . $row['fileurl']; rrmdir($directory); } The purpose of this particular bit is to run on a cron every few days. It gets "createdate" and other info from the "complete" table in order to know how old the record is. If the record is older than (in the example, 1 minute; it will be set to several days on public) the defined max age, it removes that directory and everything within it to keep the directory clean and the disk usage down. The error returned is Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/latenit2/public_html/kindleprocessor/process/garbagecleaner.php on line 46 Line 46 is Quote while($row = mysql_fetch_assoc($sql_list)) { I may be doing the look-up on the MySQL database incorrectly, too. I haven't discounted that, and I'd be thankful if someone could help me out with this issue. I have only one result being displayed in a select query result whereas I'm expecting 4 results in an array. This is my code below. $sq2="SELECT course FROM course_reg WHERE userid=?"; $stm =$conn->prepare($sq2); $stm->bind_param("s",$logged); $stm->execute (); $return2= $stm->get_result(); $r2 = $return2->fetch_all(); //print_r($r2); foreach($r2 as $course){ foreach($course as $courses){ echo $courses; } }
If I do print_r($r2); it comes out with array containing all the possible results. When i loop through the array to get individual result, it only comes out with a single result. I.e CME211 I would be glad if you can help me figure where the issue is. Thanks!!!
Hey everyone I've been working on converting my old mysql code to to the mysqli version and am running into some trouble. I am pulling posts form phpbb and displaying them in a script. My first script below works just fine. Code: [Select] <?php require("connect.php"); $query="SELECT * FROM phpbb_topics WHERE (forum_id='13' OR forum_id='14') AND topic_status = '0'"; $query2="SELECT * FROM phpbb_topics WHERE (forum_id='15' OR forum_id='16') AND topic_status = '0'"; $result=mysql_query($query); $result2=mysql_query($query2); echo "<table border=0 cellpadding=2>"; echo "<tr><td>Lost</td><td>Found</td></tr>"; while($row=(mysql_fetch_array($result)) || $row2=(mysql_fetch_array($result2))) { $forum_id=mysql_result($result,$k,"forum_id"); $topic_id=mysql_result($result,$k,"topic_id"); $topic_title=mysql_result($result,$k,"topic_title"); $forum_id2=mysql_result($result2,$k,"forum_id"); $topic_id2=mysql_result($result2,$k,"topic_id"); $topic_title2=mysql_result($result2,$k,"topic_title"); echo "<tr><td width='15%'><a href=/sahbb/viewtopic.php?f=$forum_id&t=$topic_id>$topic_title</a></td> <td width='15%'><a href=/sahbb/viewtopic.php?f=$forum_id2&t=$topic_id2>$topic_title2</a></td> </tr>"; $k++; } echo "</table>"; mysql_close($connect); ?> however its not very clean or memory efficient so i have converted it to the following. Code: [Select] <?php require("includes_database/mysqli_connect.php"); $query="SELECT * FROM phpbb_topics WHERE (forum_id='13' OR forum_id='14')"; $query2="SELECT * FROM phpbb_topics WHERE (forum_id='15' OR forum_id='16')"; $result=mysqli_query($dbc, $query); $result2=mysqli_query($dbc, $query2); echo "<table border=1 cellpadding=2>"; echo "<tr><td>Lost</td><td>Found</td></tr>"; while(($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) || ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC))) { echo "<tr><td width='15%'><a href=/sahbb/viewtopic.php?f=".$row['forum_id']."&t=".$row['topic_id'].">".$row['topic_title']."</a></td> <td width='15%'><a href=/sahbb/viewtopic.php?f=".$row2['forum_id']."&t=".$row2['topic_id'].">".$row2['topic_title']."</a></td> </tr>"; } echo "</table>"; mysqli_free_result($result); mysqli_free_result($result2); mysqli_close($dbc); ?> I know the error is in my while loop but i cant seem to figure out exactly where. The new code displays all of the first query in the table and then below that it displays the next query insted of displaying them side by side below would be an example of what is happening [table Lost Found Lost, Australian Sheppard Lost German Shepherded / Collie Mix Lost Golden Retriever/Cocker Mix Lost Female Grey Tiger Lost Pitbull Mix Lost 2 Chihuahua Lost Black Lab Lost - German Shepard Mix and Lab Mix Lost - Female German Sheperd Aprox 8 Week Old Kitten Found! 2 Pugs FOUND Found 1 Corgi female/ 1 Shih Tzu male Found Tan and Black Australian Shepard Found Australian Shepard Found Intact Male Pitbull/Lab Mix Any help that any of you could provide would be greatly appreciated! Hello, New to PHP and trying to loop through rows to and get the name of the "property" in this case. I have tried foreach and while and neither seem to want to return all rows by calling the function. Does it have something to do with echo'ing the table structure or can I not return an array out of a function like this? I commented out the while loop as that wasn't working and put in a foreach loop though that didn't return all the data either. Any help is greatly appreciated Code: [Select] <?php function getProperties(){ $sql = "SELECT propertyName FROM properties;"; $result = mysql_query($sql); //$count = mysql_num_rows($result); $property = mysql_fetch_array($result); foreach($property as $propertyName){ echo "<td width=\"157\" height=\"24\" valign=\"middle\"><div align=\"left\"><input type=\"checkbox\" name=\"$propertyName\" \"id=\"$propertyName\" />$propertyName</div></td>"; } /* for($i=0;$i>=$count;$i++){ while($property = mysql_fetch_array($result)){ $propertyName = $property['propertyName']; echo "<td width=\"157\" height=\"24\" valign=\"middle\"><div align=\"left\"><input type=\"checkbox\" name=\"$propertyName\" \"id=\"$propertyName\" />$propertyName</div></td>"; } } */ } ?> Hello, So I have a content management site set up, but I'm stuck on one part. I have a query. Code: [Select] Select `email` FROM author WHERE author.id IN(SELECT authorid FROM job WHERE id = '$_POST[id]') I'm a beginner in PHP and SQL. Basically I need the query to run, it will come out with one result and I need that to be where the email is sent to. This is the existing code I have for sending out the email $subject = " Job Application Confirmation"; $message = "Hello $_POST[name] , \r\rYou, or someone using your email address, has applied for the job: $text Using the Resource Locator at Prahan.com. Keep this as future reference. \r\r Full Name: $_POST[name] \r Location: $_POST[location] \r Email: $_POST[email] \r Additional Information: $_POST[info] \r Job ID: $id \r Job Name: $text \r \r Expect a response shortly. \r\r Regards, Prahan.com Team"; $headers = 'From: Prahan.com Team <noreply@prahan.com>'; 'Reply-To: noreply@prahan.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $to1 = 'pratik@prahan.com'; mail($to1, $result, $message, $headers); Thanks in Advance! Hello Guys, I have a column named message_status it can only have the values "read" or "unread" in it. I would like to show an image in the column next to it. If the message is "read" then I would like to display a green dot, and if it is unread I would like to display a red dot. I would also like to be able to have anything in the row that's "unread" to appear in bold. I completely stumped by this! I have written the following code, which doesn't seem to work, presumably because it is run after the table has been displayed? I am very new to this so please be gentle! Regards, AJLX $result = mysql_query("SELECT * FROM messages where username ='$username'ORDER BY {$_GET['orderbycol']} $sort"); echo "<table border='1'> <tr width='200'> <th>View</th> // code to display table removed </tr>"; $green_dot = $message_status; $red_dot = $message_status; $green = ""; $red = ""; $bold = ""; while ($row = mysql_fetch_array($result)) { echo "<tr>"; $id = $row['ID']; echo "<td><a href='/view_message.php/?view_message=$id'>View</a></td>"; echo "<td>" .$green . $red."</td>"; echo "<td>" .$bold . $message_status = $row['message_status'] . "</td>"; echo "<td>" .$bold. $row['date_sent'] . "</td>"; echo "<td>" .$bold. $row['contact_name'] . "</td>"; echo "<td>" .$bold. $row['subject'] . "</td>"; echo "</tr>"; } if ($green_dot = 'read'){ $green ='<img src=\"assets/red.jpg\"/>'; echo $green; } else { $red ='<img src=\"assets/red.jpg\"/>'; $bold = "<b>"; echo $red; this is only returning one record, when I know there are more, and it's an endless loop crashing my browser, can someone tell me how my brackets are wrong, or what is wrong? Code: [Select] if (isset($_POST['search'])){ $keyword=$_POST['keyword']; } $sql="SELECT id, fname, lname FROM obituaries WHERE lname LIKE '%$keyword%' OR fname LIKE '%$keyword%' ORDER BY id DESC"; $results = mysql_query($sql); $num = mysql_num_rows ($results); if ($num > 0 ) { $i=0; while ($i < $num) { $id = mysql_result($results,$i,"id"); $fname = mysql_result($results,$i,"fname"); $lname = mysql_result($results,$i,"lname"); ?> <a href="view.php?id=<?php echo ($id); ?>"><?php echo($fname); ?> <?php echo($lname); ?></a> <?php } } ?>Thanks in advance Hello Everyone, I have a quick question for you all, I think its fairly simple... I have created a database and I am using PHP to grab the data: $usera = $_SESSION['username']; $query2 = "SELECT * FROM tracker WHERE id = '$usera', hidden = yes"; mysql_query($query2) or die('Error, query failed : ' . mysql_error()); This hopefully will return multiple rows which look like this in the database. id username date reps hidden 1 supremebeing 2011-01-02 30 yes 4 supremebeing 2011-04-02 46 yes How would i turn each result into a variable eg: $date1 = 2011-01-02; $date2 = 2011-04-02; $reps1 = 30; $reps2 = 46; I think i have explained that well enough for you to understand, please reply if not though and i will provide more information. Thanks in Advance Hello, I am creating a class which contains one private function that deals with connecting to a SQL Server and executing the sql that is passed in to that function. I have defined a class variable which is assigned the value of sqlsrv_query like so. $this->QueryResult = sqlsrv_query($conn,$sql); I have placed private $QueryResult at the top of my class. The other public methods call this private function to assign the result set to the class variable, the private method returns and then the public methods loop through the results array like so. while($row = sqlsrv_fetch_array($this->QueryResult)) .. but the while loop never gets entered. If I declare everything in the same method then it works, however there are going to be several public methods that will use this private method and I don't want to duplicate all the database coding. Hope someone can help I have found postings close, but not close enough to find my error. I am looking up data from a MySql table and putting it in a dropdown box on a form. I can select the item, but apparently not really. I am not able to echo it, or post it to a record. I'm sure I am missing something simple, but... Code attached if anyone can show me the errors of my ways. Thank you. When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change i have a variable called $cake it needs to have this loop inside it so I can call it out Code: [Select] while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; } I tried: Code: [Select] $cake = ' while( $r = $DB->fetch_row() ){ if ( $r['last_activity'] > (time() - 900) ) $r['status'] = "<span style=float:right;><span class=desc4><b>Online</b></span></span>"; else $r['status'] = "<span style=float:right;><span class=desc4>Offline</span></span>"; $column++; if ($ibforums->member['settings']['2'] or (!$ibforums->member['id'])){ $color = "{$r['color']}"; $colors = explode(",", $color); if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ){ { $r['color'] = ($r['color']) ? "style=\"padding:1px 1px 1px 2px;color:#{$colors[0]};filter:Glow(color=#{$colors[1]},strength=3)\"":""; } }else{ $r['color'] = ($r['color']) ? "style=\"color:#{$colors[0]};text-shadow:#{$colors[1]} 2px 1px 1px\"":""; } } $test = explode(";", $info['pdata']); $r['avatar'] = ($r['avatar']) ? "<img src={$r['avatar']} width=64 height=64>" : ""; $r['star'] = ($r['star']) ? "<img class=top3 src=style_images/1/icons/{$r['star']}.png>":""; $r['name'] = "<a href=?i={$r['friendid']}>{$r['name']}{$r['star']}</a>"; $this->to_print .= <<< LOL <dl class="LOL LEFT flm" style="margin-right:5px"><dt2>{$r['name']}</dt2><dd class=padding4>{$r['avatar']}<div class="RIGHT">{$r['status']}</div></dd></dl> LOL; }'; but not working I am using a htmltable() function in FPDF and while in a MySQL While() loop I need to change the variable name each time it loops through. So basically $html needs to be $html1 on the next loop, $html2 on the next, and so on. Its probably simple, but its late and I'm tired, I can't seem to figure this one out. Here is my unfinished attempt: $htmlnum = 0; $endo = mysql_query("SELECT * FROM endorse WHERE endonum = '$endonum' AND agency = '$agency' ORDER BY ID DESC LIMIT 1"); while($endofetch = mysql_fetch_array($endo)){ $endotype = $endofetch['type']; $htmlnum = $htmlnum++; $p->htmltable($html); } I currently have a problem where I'm trying to list alot of products with the category heading only being returned once and then the long list of products within that category being listed. For Example Football boots Nike Addidas Puma etc Whereas at the moment I'm getting. Football boots Nike Football boots Addidas Football boots Puma My current code for this is as follows. <?php while($row = $db->fetchrow($stuff)) { ?> <li><a href="store-<?php echo $row['cat_id']; ?>/<?php echo seo_makeSafeURI($row['cat_title']); ?>.html"><strong><?php echo stripslashes(htmlentities($row['cat_title'])); ?></strong></a></li> <li><a href="store-<?php echo $row['cat_id']; ?>-<?php echo $row['prod_id']; ?>/<?php echo seo_makeSafeURI($row['prod_title']); ?>.html"><?php echo stripslashes(htmlentities($row['prod_title'])); ?></a></li> <?php } ?> Any help would be much appreciated. I'm trying to take a number of items from a database using a while loop and put the results into a variable so that I can send one email with all the results. I'm having trouble figuring this out though. Can anyone please give me any ideas as to how to make this work? Here's what I've done so far... all it does is result in an email with the first set of results in the while loop, not all of them. Code: [Select] <?php include("conf.inc.php"); $result = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC"); $row = mysql_fetch_row($result); $cdate = date('m-d-Y'); $sendto = "List@emails.here"; $emailsubject = "Webstats Report For $cdate."; while ($row = mysql_fetch_row($result)) { $to = $row[0]; $from = $row[1]; $subject = $row[2]; $message = $row[3]; $datetime = $row[4]; $eachmessage = "<p> <table width=\"400\"> <tr> <td> <hr width=\"400\"> To: $to<br> From: $from<br> On $datetime<br> <br> $subject<br> <br> $message </td> </tr> </table> </p>"; } $emailmessage = "<html> <body> <p>Here is a list of the messages that have been exchanged in the last 24 hours using the webstat system system.</p> $eachmessage </body> </html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Webstats <reports@webstats.com>' . "\r\n"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers); ?> Hi - To me, this doesn't make sense. My Order form uploads product weights in an array . If I echo out those weights they are fine ie 25.25 However, when I try to update the DB for some reason, the for loop strips out all but the first digit, so 25.25 becomes '2' or indeed if I had entered 9999999 it just '9' is entered in to the DB. I have tried using number_format to pre-process the decimals, - but I get an error saying you can not use it in a write format. Many Thanks to anyone who can help with this !! PS - I have abbreviated the below code for clarity: Code: [Select] $weight = $_POST['weight']; for ($i = 0; $i < $numloops ; $i++) { $sql =" UPDATE `confirmedorder` SET orderid = '$orderid[$i]', weight='$weight[$i]',status='finished', ordervalue='$ordervalue' WHERE customerid = $customerid "; $this->db->query($sql); } |