Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Please help with SELECT query
Old 01-24-2007, 11:37 AM Please help with SELECT query
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
Hi. I currently have the following select query in my PHP page.

PHP Code:
  <?$SQL mysql_query("SELECT siteName FROM Sites");
  while(
$row mysql_fetch_object($SQL)){?>  
    <tr>
      <td><?=$row->siteName;?></td>
    </tr>
  <?}?>
This quite simply gets the sitName value and creates a table row for each value. That is working fine.

However, there are only 15 entries in the table, but i want the results to create 24 rows. What i need is for the first 15 rows (or however many are in the table at that time) to display the siteName value, and the rest to be empty, or contain &nbsp;

How would i do that?
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
 
Register now for full access!
Old 01-24-2007, 11:46 AM Re: Please help with SELECT query
easdesign.com's Avatar
Extreme Talker

Posts: 154
Trades: 0
PHP Code:
$query mysql_query("SELECT siteName FROM Sites"); 
while (
$row mysql_fetch_assoc($query))
{
for (
$i 0$i 24$i++)
     {
echo 
"<tr><td>".$row['siteName']."</td></tr>";
     }

That should work
easdesign.com is offline
Reply With Quote
View Public Profile
 
Old 01-24-2007, 11:56 AM Re: Please help with SELECT query
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
That didn't quite work easdesign.com. For each of the 15 entries in the database table, 24 rows were created - giving 360 rows. I need only 24 rows. The first 15 filled with the next value from the query, and the rest containing &nbsp;
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
Old 01-24-2007, 12:07 PM Re: Please help with SELECT query
easdesign.com's Avatar
Extreme Talker

Posts: 154
Trades: 0
Oh yeah that.

PHP Code:
$query mysql_query("SELECT siteName FROM Sites"); 
for (
$j 0$row mysql_fetch_assoc($query); $j++)
{
$tablerow[$j] = $row['siteName'];
}
$j 0;

for (
$i 0$i 24$i++)
{
echo 
"<tr><td>".$tablerow[$j]."</td></tr>";
$j $j 1;

easdesign.com is offline
Reply With Quote
View Public Profile
 
Old 01-24-2007, 12:08 PM Re: Please help with SELECT query
easdesign.com's Avatar
Extreme Talker

Posts: 154
Trades: 0
Now if you have more then 24 Site names it won't display anything over that. It's going to stop at 24 Results Period. Is that going to be a problem?
easdesign.com is offline
Reply With Quote
View Public Profile
 
Old 01-24-2007, 01:26 PM Re: Please help with SELECT query
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
That is no problem at all. I always want exactly 24 rows regardless of how many entries there are.

I understand the logic behind your script, but for some reason, the array does not appear to be populating. Here is the code am using. (It is slightly different from the version i originally sent). I have added a line that displays the array. If you run the script, you can see the array is empty.

PHP Code:
   <? 
    $description
=array();
    
$price=array();
    
$SQL mysql_query("SELECT * FROM quotebreakdown WHERE projectID='$_REQUEST[projectID]' AND siteID='$_REQUEST[siteID]'"); 
    for (
$j 0$details mysql_fetch_assoc($SQL); $j++) {
      
$description[$j] = $details->description;
    } 
    echo 
'<pre>'print_r($description); echo '</pre>';?>
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
Old 01-24-2007, 01:48 PM Re: Please help with SELECT query
Veter's Avatar
Super Talker

Posts: 147
Trades: 0
Here it is:

PHP Code:
$query mysql_query("SELECT siteName FROM Sites"); 

$minrows 24$i=0$res true;
do{
    
$row mysql_fetch_object($query) ;
    if((
$i>=$minrows) && (!$row->siteName)) { 
        
$res false;
    } else {
    echo 
"<tr><td>".$row->siteName."</td></tr>";
    
$i++;
    }
} while (
$res); 
__________________
-=
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
=-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 01-24-2007, 04:37 PM Re: Please help with SELECT query
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
That did the trick. Thanks for your help guys.
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
Old 01-24-2007, 05:05 PM Re: Please help with SELECT query
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hmm...
Do you want to kill your DB???

If you have, say, 3000 records in your db, this will get the 3000 records, and stop the parsing after 24...

Try to use a LIMIT clause in your query, you will at least prevent that...
Code:
SELECT siteName FROM Sites LIMIT 24 OFFSET 0

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-24-2007, 05:09 PM Re: Please help with SELECT query
RikComery's Avatar
Average Talker

Posts: 18
Location: Essex, United Kingdom
Trades: 0
Thanks for the tip tripy. In reality i am going to have no more than 26-27 entries. It is just for a small system i am building that i intend to use at home.

It is good advice though, and i will include that as a matter of good practice.
RikComery is offline
Reply With Quote
View Public Profile Visit RikComery's homepage!
 
Reply     « Reply to Please help with SELECT query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31066 seconds with 12 queries