array that organises query output in sequences..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

array that organises query output in sequences..

Post by paulng »

with reference fo the following topic: display database record at random and ranking then by order. viewtopic.php?t=35433&highlight=

I have two tables and I would like to display the output of the code reffered in the topic above as shown in the table below.

Here is my tables and how I would like to organise my result:

Code: Select all

<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">first result </div></td>
    <td><div align="center">second result </div></td>
  </tr>
</table>
<br>
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div align="center">the rest on the result to be displyed here repetedly</div></td>
  </tr>
</table>
can anyone help? if you need further explain please post a message and I will try to elaborate.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

So you've figured out how to retrieve the data, and you're just wondering how to display it? Something like this should work:

Code: Select all

echo "<table><tr>";
while($row = mysql_fetch_assoc($result))
{
   echo <<<CELL
<td>
    $row['first_cell']
</td>
CELL;

}
echo "</tr></table>";
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

Post by paulng »

pickle,

Thanks for your reply, but I figured you didnt understand my question, I posted a question for help for a query that was displying it output as well as ranking them (e.g 1 to 10). let say if item1 is ranked 2 item2 is ranked 5 and item6 is ranked 5 item7 is ranked 2

this will output :
item 1 && item7 :random
item2
item6

this was achieved in the code from the previous posted question, however it is easy to display these out put using one cell. if you pay attention to the table I provided where the first item of the array will display in the first cell , the second item in the second cell and the rest in the row below.

not sure if it is now clear on what i want to achieve....Thanks!
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Okay, that's less clear to me now :?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

so if they are ranked the same, you want to display them randomly?

if so, you could put the identical rankings into an array and then use array_rand() to grab them out randomly.
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

Post by paulng »

all I want is to a type of recordset that display the first output in the first table first cell, the second output in the first table second cell. and the remaining result to be displayed inthe second table which has only one cell.


the random ranking functionality has been achieved using this code:

Code: Select all

$sql_query = "SELECT * FROM $tablevar WHERE FIND_IN_SET('download',DisplayOn) AND StartDate <= '$currdate' AND EndDate >= '$currdate' ORDER BY RAND()"; 
$rs_data = mysql_query($sql_query) or die ("could not execute query: " . mysql_error()); 

while($data = mysql_fetch_assoc($rs_data)) 
{    

$arr_data[$data['DisplayOrder']] = $data; 
} 

ksort($arr_data); 

foreach($arr_data as $item)
but this code works with only what cell which replicates in self..
Post Reply