This is what I had $variable = mysql_fetch_array(mysql_query("SELECT * FROM mystuff WHERE id>'0' ORDER BY id DESC LIMIT 1")); PHP: After that linethe $variable variable is used a lot of times to display one row... Now I have decided that I need to pull more than one row, so I made this loop: $get = mysql_query("SELECT * FROM $tab[tourney] WHERE id > 0 ORDER BY id DESC LIMIT 3"); while ($newvariable = mysql_fetch_array($get)) { return = $newvariable } $newvariable = $variable; PHP: i know I can't use the return to get the variable from the loop, but what can I do to pull more than one row? Or what can I do to get the newvariable from the loop if its possible? I cannot place the { bracets very far from eachother. I have html content and then php and html again, it will be a big mess.
First of all your post query will give error. U missed semi colon @ line 3. Use echo to show the variable value or put all the result in to a array and then show them. Simple............ ---------------------------------------------- Download Free Ebooks Banking Interview Questions Answers | Interview Tips
I just wrote it so you get the idea, it's not the actual code, it would be too long to put here. the loop ends with } how can I pull the values inside the loop?
$get = mysql_query("SELECT * FROM $tab[tourney] WHERE id > 0 ORDER BY id DESC LIMIT 3"); $x = array(); while ($newvariable = mysql_fetch_array($get)) { $x[] = $newvariable['value']; } $variable = $x; PHP:
It will not be a mess if you use PHP editor software which auto highlight both pair of brackets / curly brackets if you click on one. First of all, do you get an error or what? and what do you mean by pull more than 1 row? I can help you but I need an example / more details
PHP Code is a mess period, but if you want cleaner code, I just posted on another thread: USE CodeIgniter
Here i'm sharing a piece of code from one of my works.. I used some functions for db works...like executequery, getNumRows etc. Hope this will have some idea to get values using loop from mysql queries. $q="select * from employee_training where training_id=$t_id"; $res2=executeQuery($q); $row=getNumRows($q); $k=0; while ($rs = mysql_fetch_array($res2)) { $tr[$k]=$t_id; $id[$k]=$rs["employee_id"]; $adid[$k]=$rs["added_by_id"]; $lu[$k]=$rs["last_update"]; $k++; } if($row>0) { $remarks=" <table style='font-size:12px; color:#0066FF;' width=418 border=1 cellpadding=2 cellspacing=0 bordercolor=#f0f0f0> <tr> <td><b>Training ID</b></td> <td><b>Employee ID</b></td> <td><b>Added By</b></td> <td><b>Updated On</b></td> </tr>"; for ($k=0;$id[$k]!=NULL;$k++) { $remarks.=" <tr> <td>$tr[$k]</td> <td> <a href=id_search.php?iid=$id[$k] target=_blank>$id[$k]</a></td> <td><a href=id_search.php?iid=$adid[$k] target=_blank>$adid[$k]</a></td> <td> $lu[$k]</td> </tr>"; } $remarks.="</table>"; $init=0; } else if ($row==0) { $remarks="<font style='font-size:10px; color:#0066FF;'>No Information Found for this Training.</font>"; $init=1; } Code (markup): Rep me if it helps you!