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.

PHP Forum


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



Freelance Jobs

Reply
Old 01-18-2005, 08:20 AM if statement
Experienced Talker

Posts: 32
Trades: 0
i have the following code:

<?php
include password.inc");

$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't find databse");

/* Select pets of the given type */
$query = "SELECT * FROM blah";
$result = mysql_query($query)
or die ("Couldn't execute query.");



while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
/*display row */
echo "<tr>\n";

echo "<td class='content' bgcolor='#ebebeb'>
<a href='actor.php?actor_id={$row['StarID']}'>{$row['Star_Name']}</a> \n</td>";
echo "</tr>\n";
}
?>

how do i change this so that it only displays the data if there are matching records in my database?
hershel is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-18-2005, 09:40 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
What do the database records have to match with? At the moment you are just pulling all the info from one table. If you only want some of the data, you need a WHERE clause in your SQL, or some php to decide whether or not to echo out the table row.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 01-18-2005, 02:25 PM
Experienced Talker

Posts: 32
Trades: 0
basically this is part of a table. I want it so that if there is any data in 'Star_Name' for this record then it is displayed. But if there isn't then i don't want {$row['Star_Name']} to show up at all (because it will just be blank
hershel is offline
Reply With Quote
View Public Profile
 
Old 01-18-2005, 03:54 PM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Trades: 0
Oberon's right, do it with your SQL statement, like " SELECT * FROM blah WHERE Star_Name <> NULL "

Then test the results like:

PHP Code:
$num_rows mysql_num_rows($result);
if (
$num_rows >= 1
{
  
//You've got at least one record
  
echo '<table>';

    while (
$row mysql_fetch_array($result,MYSQL_ASSOC))
    {
        
/*display row */
       
echo "<tr>\n";
       echo 
"<td class='content' bgcolor='#ebebeb'>
        <a href='actor.php?actor_id=
{$row['StarID']}'>
            
{$row['Star_Name']}
        </a> \n</td>"
;
        echo 
"</tr>\n";
     }

  echo 
'</table>';

__________________

Please login or register to view this content. Registration is FREE

Last edited by Phaedrus; 01-18-2005 at 06:32 PM.. Reason: use [PHP] tags
Phaedrus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to if statement
 

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.13659 seconds with 12 queries