PHP - While Loop Mysql_fetch_array Single Output
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"; } ?>() Similar TutorialsI want to use all five results separately in order to use in a Jquery slider. Code: [Select] <?php $a = "SELECT * FROM blog_posts ORDER BY id DESC LIMIT 5"; $query = mysql_query($a) or die (mysql_error()); $query_results = mysql_fetch_array($query); ?> I know if i was going to grab vars from an normal array i would just use... Code: [Select] <?php echo $array_reults['0'] ?> Can any one help me with this problem? hi i need help on posting multiple inputs in a single button...while using mysql_fetch_array here is my codes: <? $re6 = mysql_query('select username from users where course = "BSIT" and yearlevel = "FOURTH"'); ?> <br /> <h1>Post Grade</h1> <h1>IT, Fourth Year</h1> <br />Please fill the following form to send The Grade<br /> <? $n = 0; while($row = mysql_fetch_row($re6)) { echo'<form action="grade_post.php" method="post">'; echo'Recipient<span class="small">(Username)</span><input type="text" value="'.$row['username'].'" readonly="readonly" id="recip" name="recip[' . $n . ']" />'; echo'Subject<input type="text" value="'.htmlentities($otitle, ENT_QUOTES, 'UTF-8').'" id="title" name="title[' . $n . ']" />'; echo'<input type="hidden" value="FOURTH" id="year" name="year[' . $n . ']" />'; echo'<input type="hidden" value="FIRST" id="sem" name="sem[' . $n . ']" />'; echo'Grade<input type="text" id="message" name="message[' . $n . ']" ><br />'; ++$n; } ?> i get all my recipients in every input type, but when i tried to post it in my database not all of them are posted rather only one of them are posted in my database ...what i want to happen is that all of my recipients in every input type will be posted in my database with different ids'...help pls... Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. This 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 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."; } } 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 came up with this but it outputs the value 3 times... (because there are 3 variables) ie mathsmathsmaths How do I fix this or do it the correct way? Thanks Code: [Select] $subject = "maths"; $phone = "1235"; $colour = "red"; $all_vars = compact("subject", "phone", "colour"); get_value($subject); function get_value($variable){ global $all_vars; foreach($all_vars as $key=>$value){ if ($key = $variable) { echo $key; } } } Okay, I have a question. Is there a way to combine three fields within a single table (x, y, z) into a single variable? Something like: x~y~z? (the ~ would be needed)
Hi, I have a table of content in my page. For each row it has a check box. How do i achieve the function of when i click on submit button, those rows which are checked will be downloaded as a single pdf file. For example, for each checked row is a PDF file here. Suppose if i checked for 5 rows , 5 PDFs will be downloaded. Hi, I'm modifying the following PHP code from a Wordpress plugin: /* Byline. */ if ( $instance['byline'] ) echo do_shortcode( "<p class='byline'>{$instance['byline']}</p>" ); /* Entry title. */ if ( 'widget' !== $instance['entry_container'] && $instance['entry_title'] && $show_entry_title ) { the_title( "<{$instance['entry_title']} class='entry-title'><a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a></{$instance['entry_title']}>" ); } elseif ( 'widget' !== $instance['entry_container'] && $show_entry_title ) { the_title( "<a href='" . get_permalink() . "' title='" . the_title_attribute( 'echo=0' ) . "' rel='bookmark'>", "</a>" ); } The output currently is: Code: [Select] [ December 13, 2010 ] Post Title I'm trying to combine the two so that the output appears on one line. What is the operator to execute multiple command in one statement? Thanks. 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 have a while loop that builds up a table of records, each row has a button that needs to have an action to delete that specific record. I can think of the obvious way around this and add a form around each row and set the button to type="submit". However there is a problem i have the entire table of records wrapped within in a form object for other functionalities. Does anyone have a solution for this problem? I am trying to write some code for my website. I pull information out of a database using a while loop. What am I trying to figure out is how to change some of the information. Some of the information used by the database is not there. It is not there cause I lost it and don't know what to put in place. The missing information is a Date Field. In the database if the field is blank it displays 0000-00-00. On the page it displays 01-01-1970. What I want to do is when the date is 01-01-1970 it actually shows N/A. How would I go about doing this? This is the code that I am using to draw the information from the database. Code: [Select] if ($year == 'other') { $sqlC = "SELECT * FROM `ttmautos` WHERE YEAR(date_return) < 2008 ORDER BY `date_return` DESC"; $resultC = mysql_query($sqlC) or die(mysql_error()); if (mysql_num_rows($resultC) == 0) { echo "There currently are no signatures in the database from $year"; } else { $autographs = "<table id='ttm'>\n"; $autographs .= "<tr class='first'><th>Player</th><th>Date Sent</th><th>Date Returned</th><th>Item Signed</th><th>Project</th></tr>\n"; $autographs .= "<tr><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td></tr>\n"; while ($row = mysql_fetch_assoc($resultC)) { $category = $row['category']; $fname = $row['f_name']; $lname = $row['l_name']; $dsent = date('m-d-Y', strtotime($row['date_sent'])); $dreturn = date('m-d-Y', strtotime($row['date_return'])); $ireturn = $row['item_return']; $project = $row['project']; $autographs .= "<tr><td class=\"auto_cell\">$fname $lname</td>"; $autographs .= "<td class=\"auto_cell\">$dsent</td>"; $autographs .= "<td class=\"auto_cell\">$dreturn</td>"; $autographs .= "<td class=\"auto_cell\"><a href=\"signatures.php?c=$category&l=$lname&f=$fname\">$ireturn</a></td>"; $autographs .= "<td class=\"auto_cell\"><a href='projects/$project.php'>$project</a></td></tr>\n"; } $autographs .= "</table>"; echo "$autographs"; } } } I hope that I have given enough information to help me out with this issue. Hi! This bit of code does exactly what I want it to just not sure why. The way I would (***_u_me) this code to be written would be to replace the echo ($array_2[$index]); with echo ($array_2[$value]); to get the output I'm getting. Basically the foreach loop loops through $array_1 when it finds a key with a null value it outputs the $value or the $index which ever I decide to output of $array_2 which corresponds to that value. when I echo ($array_2[$value]) I get no output and when I echo ($array_2[$index]) I get the wanted output below. It doesn't seem right <?php function test() { $array_1 = array("Matt" => NULL, "Kim" => 1, "Jessica" => NULL, "Keri" => 1); $array_2 = array("Matt","Kim","Jessica","Keri"); foreach ($array_2 as $index => $value) { if (!isset($array_1[$value])) { echo ($array_2[$index]); echo "<br />"; } } } test(); ?> output Matt Jessica Thanks, steadythecourse Hi
I am having problems running a while loop twice. The first loop runs fine but the 2nd one does not run. Can anyone please advise why this is? My code is below
Thanks in advance.
Jonathan
$sql = "SELECT id, url, time FROM fyi_links"; $res = odbc_exec($con, $sql); while ($row = odbc_fetch_array($res)) { print($row['id'].",".$row['url'].",".$row['time']."\n"); } //Run loop again after some other code while ($row = odbc_fetch_array($res)) { print($row['id'].",".$row['url'].",".$row['time']."\n"); } Folks, I have an array having domain names & i have Coding for checking each element of this $valid array in an API and extract Information from XML. BUT, looks like the this code is not working or i am possibly not able to integrate this code properely. Another thing, this API allows to Check 19 Domain Max at a time, so this counter is already there in the code. Here is the Code: if(empty($valid)) return NULL; $rows=array(); while(count($valid)) { $this_set=array(); $count=0; while($count<19 && count($valid)) { $url=array_shift($valid); $this_set[]='item'. $count . '='. urlencode($url); $count++; } if(!count($this_set)) break; $query='http://lightapi.majesticseo.com/api_command.php?app_api_key=API_KEY&cmd=GetIndexItemInfo&items='. $count .'&' . implode('&',$this_set); $content=file_get_contents($query); preg_match('@<DataTable.*?Headers=\"(.*?)\"@',$content,$info); $headers=explode('|',$info[1]); preg_match_all('@<Row>(.*?)</Row>@',$content,$info); foreach($info[1] as $line) { $data=explode('|',$line); $info=array_combine($headers,$data); $rows[]=$info; } } if(empty($rows)) return NULL; return $rows; } I want to echo the output with: echo $Domain['Item'] .' '. $Domain['ACRank'] .' '. $Domain['ExtBackLinks'] .'<br />'. PHP_EOL; Could someone please help with this code? Regards Natasha T Hey everyone, I've just undertaken my first PHP project and I'm trying to build an HTML table that lists businesses by category. The problem I am having is that the output of the PHP shows the first record in the first row both columns and this happens with every record after that. The Code: <?php // Set the error(s) reporting level error_reporting(E_ALL); ini_set("display_errors", 1); $category = "Professional Services"; // Open a connection link to your Database Engine $link = mysql_connect('localhost', 'liecon63_bizdir', 'pass') or die("Connection Error : " . mysql_error()); // Select the database to work with mysql_select_db('liecon63_bizdir') or die("Database Selection Error : " . mysql_error()); // Define your query $sqlquery = "SELECT * FROM bizdir WHERE bizcategory = '".$category."'"; // Execute the query (returning a result set in this case $sqlresult = mysql_query($sqlquery) or die("Query Error : " . $sqlquery . "<br /> Error: " . mysql_error()); // Validate that the query returned records if (mysql_num_rows($sqlresult) > 0) { // Start display of the records echo "Business Category : " . $category . "<BR />"; echo "<table>"; // Loop through your result set to process the results while ($row = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) // here you can simply use mysql_fetch_assoc() instead { // Process your records here... like ?><table border="0" width="100%" id="table3"> <td width="400"><tr> <td><?php echo $row['bizname']; ?> <br> <?php echo $row['bizaddress']; ?> <br> <?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?> <br> <?php echo $row['bizphone']; ?></td> <td><?php echo $row['bizname']; ?> <br> <?php echo $row['bizaddress']; ?> <br> <?php echo $row['bizcity']; ?>, <?php echo $row['bizstate']; ?> <?php echo $row['bizzip']; ?> <br> <?php echo $row['bizphone']; ?></td> </tr> </table> <? } echo "</table>"; } else { echo "No records have been found for the category " . $category; } // Close your Db Engine Link mysql_close($link); ?> The Output: <BODY onLoad="changeBkg()" id="body" TEXT="#000000" LINK="#FF0000" ALINK="#FF0000" VLINK="#FF0000"> Business Category : Professional Services<BR /><table><table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Blumstein Accounting <br> 1476 Blue Spruce Lane <br> Wantagh, New York 11793 <br> (516) 221-6161</td> <td>Blumstein Accounting <br> 1476 Blue Spruce Lane <br> Wantagh, New York 11793 <br> (516) 221-6161</td> </tr> </table> <table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Sachem Dental Group <br> 470 Patchogue Holbrook Rd <br> Holbrook, New York 11741 <br> (631) 589-8485</td> <td>Sachem Dental Group <br> 470 Patchogue Holbrook Rd <br> Holbrook, New York 11741 <br> (631) 589-8485</td> </tr> </table> <table border="0" width="100%" id="table3"> <td width="400"><tr> <td>Care Plus Chiropractic <br> 1150 Sunrise Highway <br> Bayshore, New York 11706 <br> (631) 665-1150</td> <td>Care Plus Chiropractic <br> 1150 Sunrise Highway <br> Bayshore, New York 11706 <br> (631) 665-1150</td> </tr> </table> </table></html> Please HELP! How can I make this output in descending order from greatest to least? Right now, it appears like: 1940 1941 1942 1943 1944 etc... i'd like it to be like 2012 2011 2010 2009 etc.. until it gets to 1940 any ideas? here is my code: <? $i = 1939; while ($i < 2012) { $i++; echo '<option value="'.$i.'">'.$i.'</option>'; } ?> PHP script return 20 UL LIST values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D |