herghost Posted October 13, 2010 Share Posted October 13, 2010 Hi all, I have a page which simply pulls info from a database by id: <?php include ('connect.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM JOBS WHERE id=$id"); if (!$query) { echo "Could not run query: " . mysql_error(); exit; } $row = mysql_fetch_row($query); { echo "<body><h3>" . $row[1]. "</h3>"; echo "<h4>" . $row[2] . "</h4>"; echo "<h4>" . $row[3] . "</h4>"; echo "<h5>Duties & Responsibilities:</h5><ul>"; echo "<li><strong>" . $row[4] . "</strong>" . $row[5] . "</li>"; echo "<li><strong>" . $row[6] . "</strong>" . $row[7] . "</li>"; echo "<li><strong>" . $row[8] . "</strong>" . $row[9] . "</li>"; echo "<li><strong>" . $row[10] . "</strong>" . $row[11] . "</li>"; } ?> However in some cases the rows in the database may only contain data upto row 6 for example, how would I go about coding this so that it only displays rows that exist. If row 6 exists then 7 always will too as the information is connected. I am manually added this stuff into phpmyadmin as I do not need a form as once it is complete then it will not need to be added to. Also row 8 and 9 may contain data but 6 and 7 may not Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/215802-row-echo-help/ Share on other sites More sharing options...
AbraCadaver Posted October 13, 2010 Share Posted October 13, 2010 Something like this assuming that if $row[6] is not empty then $row[7] will not be empty: echo !empty($row[6]) ? "<li><strong>" . $row[6] . "</strong>" . $row[7] . "</li>" : ""; Quote Link to comment https://forums.phpfreaks.com/topic/215802-row-echo-help/#findComment-1121878 Share on other sites More sharing options...
herghost Posted October 13, 2010 Author Share Posted October 13, 2010 Fantastic thanks Quote Link to comment https://forums.phpfreaks.com/topic/215802-row-echo-help/#findComment-1121906 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.