Forum Moderators: coopster

Message Too Old, No Replies

Getting Multiple Results From Database And Echoing Them Correctly

Echo Data Correctly

         

jeremaitland

11:12 pm on Jul 25, 2010 (gmt 0)

10+ Year Member



So Im Sure This Is Going To Be A Simple Solution To My Problem But Im Having A lot of issues getting the solution. I am Looking To get data from my database and displaying the rows of information in different areas of my web page. So i guess im just having the problem of splitting up the rows and displaying them in different areas. I am able to get the information and echo them correctly but if i have more than one row it displays them all directly below themselves and i don't want this.
Can Anyone Please Help? Thanks

rocknbil

2:41 am on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard jeremaitland, condense the code to it's smallest denominator (i.e., under 100 lines, the less the better) and let's see what you've done so far.

jeremaitland

3:00 am on Jul 26, 2010 (gmt 0)

10+ Year Member



$R1 = mysql_query("select * from AnnArbor where Active='0' AND Pending='0' ORDER BY ID LIMIT 8");

<? while ($recentdeal = mysql_fetch_array($R1)) {?>
<tr>
<td width="36%" valign="top"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#CCFF99">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><? echo $recentdeal['Deal Name'] ?></td>
</tr>
<tr>
<td width="36%">&nbsp;</td>
<td width="64%" rowspan="7" align="center" valign="middle"><img src="" alt="" width="175" height="115" align="absmiddle" /></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>Price:<? echo $recentdeal['Price'] ?></td>
</tr>
<tr>
<td>Value:<? echo $recentdeal['Value'] ?></td>
</tr>
<tr>
<td>Savings:<? echo $recentdeal['Savings'] ?></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>Expired:<? echo $recentdeal['EDay'] ?>
</td>
</tr>
</table></td> </tr>
</table></td><? }?>



This echo's the information in the correct area but if their is more than one row it echos the next row below it i want to be able to echo the next row somewhere else on the page. Hope this kind of makes since.

rocknbil

5:04 pm on Jul 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps something like this?


$records = Array();
$R1 = mysql_query("select * from AnnArbor where Active='0' AND Pending='0' ORDER BY ID LIMIT 8");
while ($recentdeal = mysql_fetch_array($R1)) {
array_push ($records,
Array (
'Deal Name' =>$recentdeal['Deal Name'],
'Price' => $recentdeal['Price'],
'Value' => $recentdeal['Savings'],
'EDay' => $recentdeal['EDay']
)
);
}


My syntax may be incorrect, typed out quickly, but you can see the logic. You create a list array $records on which you push the anonymous unnamed associative arrays for each record. You can then access individual items anywhere you want on the page.

Alternatively and a bit more clunky you could use scalar variables or $$variable variables.

Not a great idea for large record sets but with a limit of 8, should work fine.