runnerjp Posted December 8, 2007 Share Posted December 8, 2007 <?php session_start(); require_once '../settings.php'; $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } }else{ echo '<img src="images/pic.jpg">'; } ?> where it says no users with id.. how can i make it so only that comes up as at the moment it shows no users with id but also shows the other information? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Change your logic so when the record is found you do the rest of your code, and if not, it returns the error and then their is no code after. You only want to take action if it found what you want it to. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 ok so could i have example to work with or link as i dont quite get you lol Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Something like this <?php session_start(); require_once '../settings.php'; $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } } else { echo '<img src="images/pic.jpg">'; } } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 ohhh so have the bumph 1st then add no user last ahh that makes sence Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Yeah, I wasnt sure what you were actually doing, but you want it to flow logically. No point going through all the code if one part isn't valid right? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 ah yes buuuuut what if you want to add a table into the mix <?php session_start(); require_once '../settings.php'; $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } } else { echo '<img src="images/pic.jpg">'; } } else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> <table width="100%"> <tr> <td colspan="3"><div align="center">Welcome to <?echo "$puser"?>'s profile</div></td> </tr> <tr> <td width="162">your id is no <?echo "$pid"?></td> <td width="711"></td> <td width="100"> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 You only want to add the table if there was an ID, so you'll have to mix it with your PHP. You can either keep PHP on and use echo or you can exit PHP, do the HTML, then turn PHP back on. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 what would be the best way?? how would i turn php off if their is no id then turn it back on again :S Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 No best way really, it's your preference. And you just do this: <?php echo "PHP is on"; ?> HTML is on <?php echo "PHP is back on"; ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 ahh yer but i have php in my table... dam lol how would i mix it in the the php?? sorry lots of questions but you explain it well Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 The exact same way <table> <tr> <td>HTML</td> <td><?php echo "PHP" ?></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 oh no ok i can allready do that just i dont want the table to apear if no id is found Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Right, so you put that part up in the code where the ID is found. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 what would i just echo it? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Up to you. Either echo or turn off PHP, do your html, then turn php back on. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 yes but i dont get how that works to echo a table Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 echo "<table><tr><td>Hi</td></tr></table>"; Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 ok i tried <?php session_start(); require_once '../settings.php'; $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } } else { echo '<img src="images/pic.jpg">'; } } echo '<table width="100%"> <tr> <td colspan="3"><div align="center">Welcome to <?echo "$puser"?>'s profile</div></td> </tr> <tr> <td width="162">your id is no <?echo "$pid"?></td> <td width="711"></td> <td width="100"> </td> </tr> </table> ' else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> but get unexpected T_STRING, expecting ',' or ';' on line 31 Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 You are already in PHP since you used Echo so this line isnt valid <td colspan="3"><div align="center">Welcome to <?echo "$puser"?>'s profile</div></td> you just need <td colspan="3"><div align="center">Welcome to '.$puser.'\'s profile</div></td> Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 You also may have it placed wrong since I dont see a ending } and you dont have a semi colon at the end. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 so hav ei put it wrong by just echoing it Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 <?php session_start(); require_once '../settings.php'; $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $pemail = $array['Email']; $puser = $array['Username']; $pid = $array['ID']; $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$pid' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } } else { echo '<img src="images/pic.jpg">'; } } echo '<table width="100%"> <tr> <td colspan="3"><div align="center">Welcome to '.$puser.'\'s profile</div></td> </tr> <tr> <td width="162">your id is no '.$puser.'</td> <td width="711"></td> <td width="100"> </td> </tr> </table> else { echo "No users found with id $id<br />"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> getting Parse error: syntax error, unexpected T_ELSE, expecting ',' or ';' in /home/runningp/public_html/members/profile.php on line 50 Quote Link to comment Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 You need a ending quote ' after your /table and you need a semicolon ; to end the statement as well as a } probably too. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 8, 2007 Author Share Posted December 8, 2007 echo '<img src="images/pic.jpg">'; } } { echo '<table width="100%"> <tr> <td colspan="3"><div align="center">Welcome to '.$puser.'\'s profile</div></td> </tr> <tr> <td width="162">your id is no '.$puser.'</td> <td width="711"></td> <td width="100"> </td> </tr> </table'>; tried it and didnt respond well lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.