Jump to content
rootKID

how to make IF with higher then (words)...?

Recommended Posts

Hello w3 again... what im trying to is that im making a request page. and in this request page, then instead of taking the whole imdb URL out from the DB.then how can i do with a if so there is going to stand "Yes" if filled and "NO" if not?... i have tried this: echo "<td>".if(mysql_num_rows($r_row['r_imdb_link']) > 0){echo "Yes";}else {echo "No";}."</td>"; but got a error... but i also tried with a fetch_assoc before the num_rows... and that was the same... error was this: Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\ss_tracker_2011\request.php on line 101 and with num rows this: Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\ss_tracker_2011\request.php on line 101 The very same...ideas?... (Pictures added what i ment if no ideas got from my own words...)

  • Like 1

Share this post


Link to post
Share on other sites

but its the same code... isn't it... what have you changed?... EDIT: well... it works... kinda... now i just see the word 'no' inside the boxes, and right beside it inside the box also this: Warning: mysql_num_rows() expects parameter 1 to be resource, string given inC:\xampp\htdocs\ss_tracker_2011\request.php on line 133 No

ideas?...

Edited by rootKID

Share this post


Link to post
Share on other sites
but its the same code... isn't it... what have you changed?... EDIT: well... it works... kinda... now i just see the word 'no' inside the boxes, and right beside it inside the box also this: Warning: mysql_num_rows() expects parameter 1 to be resource, string given inC:\xampp\htdocs\ss_tracker_2011\request.php on line 133 No

ideas?...

he just added the semicolonthis is your code
echo "<td>".if(mysql_num_rows($r_row['r_imdb_link']) > 0){echo "Yes";}else {echo "No";}. "</td>";

notice where it start from echo to the second quote, theres no semicolon, so he just added the missing semicolon.then he placed the IF statement on another line, then the last echo statement on its own line and close it off, you was just missing the semicolon. from what i see

Share this post


Link to post
Share on other sites

the '.' concatenation operator is used to join VARABLES together that at the end will produce a string output, you can't join if conditions and such like, and that is why you recieved the error about 'unexpected T_IF'. the 'Warning: mysql_num_rows() expects parameter 1 to be resource' suggests it is not receiving the variable reference to mysql_query() correctly.

Share this post


Link to post
Share on other sites

hmm... thanks for the increased knowledge! :)... but still.. i dont see how it should not get the whole SQL/Variable... this is the whole page code:

<?phpinclude ("include/config.php");include ("include/database.php");include ("include/functions.php");?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><link rel="stylesheet" href="styles/<?php echo $css_file; ?>.css" type="text/css" /><link rel='shortcut icon' href='<?php echo $icon_name; ?>.ico' /><script type="text/javascript" src="scripts/java_klappe.js"></script><title><?php echo $sitename; ?></title></head><body> <center><div id="header"><?php include ("header_div.php"); ?></div></center> <center><div id="status_bar"><!--STATUS BAR--><div class="status_left"><?php include ("status_left.php"); ?></div><!--/********************/--><div class="status_right"><?php include ("status_right.php"); ?></div></div><!--STATUS BAR--></center> <center><div id="menu"><?php include ("menu.php"); ?></div></center> <center><div id="content_body"><center><!--/**********************/--><?php$req_added_succes = $_GET['req_added_succes'];if($req_added_succes){echo "Request added Succesfully!";} echo begin_box(" ");echo "<a href='request.php'>View Requestes</a> ";echo "<a href='request_add.php'>New Request</a>";echo end_box();echo "<br />";  echo begin_box("<center>View Requestes</center>"); $req_query = "SELECT * FROM requestes";/*$req_query = "SELECTrequestes.r_id,requestes.r_title,requestes.r_category,requestes.r_imdb_link,requestes.r_votes,requestes.r_descr,requestes.r_uID,requestes.r_date,requestes.r_completed,categories.id,categories.name,categories.image,categories.cat_desc,users.id,users.usernameFROMrequestes INNER JOINusers ON requestes.r_uID = users.idINNER JOINcategories ON requestes.r_category = categories.id";*/  $req_result = mysql_query($req_query)or die(mysql_error());if(mysql_num_rows($req_result) > 0){echo "<table id='request_view_page_table_start' align='center' border='1'>";echo "<tr>";echo "<td>Request Name</td>";echo "<td>Category</td>";echo "<td>Added</td>";echo "<td>IMDB</td>";echo "<td>Votes</td>";echo "<td>Completed?</td>";echo "<tr>";while($r_row = mysql_fetch_assoc($req_result)){echo "<tr>";echo "<td>".$r_row['r_title']."</td>";echo "<td>".$r_row['r_category']."</td>";echo "<td>".$r_row['r_date']."</td>"; /*IMDB Yes/No BOX*///echo "<td>".if(mysql_num_rows($r_row['r_imdb_link']) > 0){echo "Yes";}else {echo "No";}."</td>";echo "<td>";if(mysql_num_rows($r_row['r_imdb_link']) > 0){echo "Yes";}else {echo "No";}echo"</td>";//echo "<td>".$r_row['r_imdb_link']."</td>";/*IMDB Yes/No BOX*/ echo "<td>".$r_row['r_votes']."</td>";echo "<td>".$r_row['r_completed']."</td>";echo "<tr>";}//While ends...echo "</table>";}//If ends...else {echo "<center>There is no Rquestes Yet</center>";}echo end_box();?><!--/**********************/--></center></div></center> <center><div id="footer"><?php include ("footer.php"); ?></div></center></body></html>

so it should take it correctly, since im giving a * for it as a beginning... and then i could myself later on put on the required stuff... that was the plan at least :).. EDIT: Could it be possible that it cannot read the variable called ($r_row) since its outsite the if statement?...

Edited by rootKID

Share this post


Link to post
Share on other sites

mysql_num_rows requires a mysql resource. You are passing it a string. In your code, $req_result would be the resource. mysql_num_rows would be used to check if any data was returned from the query. You are trying to check if a specific field has been filled in, not whether any data matched your query. Your if statement should look something like this:

if($r_row['r_imdb_link'] != '')

or

if(!empty($r_row['r_imdb_link']))

Also, regarding your original question about the if statement, you could use the ternary syntax. It's basically a condensed if statement:

echo "<td>".(($r_row['r_imdb_link'] != '')?"Yes":"No")."</td>";

Share this post


Link to post
Share on other sites

well... thanks... but one question, just to play a little stupid... the third one you posted... the code, what do you mean?... i mean. the syntax... its doing the same?.. and i did knew about the if(!empty($r_row['r_imdb_link'])) part... but not the syntax after that... like this: ?"yes":"no").Ect... what does that syntax mean?... EDIT: by the way... thanks... working now... now what if i wish to put colors on the yes/no words... could i just put a normal div-box around them and then style them customly by there?... EDIT #2: what shall i edit in the SQL to make the latest Added showed up on the top?... not just DESC?... because i did, and it does shows up... but after i created 2, 1 called game of thrones and one this: 312414 then the second should be at top and not game of thrones, but the game of thrones was still at top... somfthing to do with the names?..

Edited by rootKID

Share this post


Link to post
Share on other sites
well... thanks... but one question, just to play a little stupid... the third one you posted... the code, what do you mean?... i mean. the syntax... its doing the same?.. and i did knew about the if(!empty($r_row['r_imdb_link'])) part... but not the syntax after that... like this: ?"yes":"no").Ect...what does that syntax mean?...
Check out this link:http://us.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
now what if i wish to put colors on the yes/no words... could i just put a normal div-box around them and then style them customly by there?...
I would use a span rather than a div, but yes.
what shall i edit in the SQL to make the latest Added showed up on the top?... not just DESC?... because i did, and it does shows up... but after i created 2, 1 called game of thrones and one this: 312414 then the second should be at top and not game of thrones, but the game of thrones was still at top... somfthing to do with the names?..
Use the ORDER BY clause to change the way the records are sorted. Assuming that r_date is the date the record was added you could adjust your query like so:
$req_query = "SELECT * FROM requestes ORDER BY r_date DESC";

If r_date is not the date you entered the record, you could use another field like the id (if the id is an auto-incremented field). The point is, you need to have a way to track the order in which the records were entered.

Share this post


Link to post
Share on other sites

ok, thanks alot body! :)... and just tell if i ask to much, but any idea about this one?: http://w3schools.invisionzone.com/index.php?showtopic=43680 Thanks if possible :)..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×