jimmi8 Posted February 4, 2007 Share Posted February 4, 2007 HI, I have this piece of code that set the query string depending on if a particular row is pulled from the database. The row in question is the one ive assigned to the variable upload. If it is set then one query string gets used and if it isnt another one gets used: $sql = "SELECT entries.*, categories.*, uploads.* FROM entries INNER JOIN categories ON(categories.category_id = entries.category_id) LEFT JOIN uploads ON (uploads.blog_id = entries.blog_id) ORDER BY entries.date_submitted DESC LIMIT 3"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { $title = $row['title']; $body = substr($row['body'],0,400); $author = $row['author_id']; $date = $row['date_submitted']; $cat = $row['category_id']; $cat1 = $row['category']; if(isset($row['upload_id'])) { $upload = $row['upload_id']; } else { $upload = NULL;} $blog_id = $row['blog_id']; ?> <li><h3><?php echo $upload; ?><?php if(isset($upload)) { echo '<a href="individualarticle.php?f=1&blog_id=' .$blog_id;} else { echo '<a href="individualarticle.php?f=0&blog_id=' .$blog_id;} ?> "><?php echo $title; ?></a><?php if(isset($upload)) { echo ?><img src="pin.gif" /><?php ;}?></h3><p style="color: red; display: inline;">written by <?php echo $author; ?> on <?php echo $date; ?> Posted in<a href="categorypage.php?category_id=<?php echo $cat; ?>"><?php echo $cat1; ?></a></p><p><?php echo $body; ?></p></li> <p><a href="individualarticle.php?blog_id=<?php echo $blog_id ?>">read on...</a></p> Now it seems to work fine. If the row is set i can click through to the next page and everything works. The problem is that if the row is not set and the else is called and second query string gets used the $blog_id varaible doesnt get passed to the $_GET. When you click through the query string gets in to the url but theres no $_blog_id number on the end. I cannot for the life of me work out why. Could anyone spot the problem? Quote Link to comment Share on other sites More sharing options...
alpine Posted February 4, 2007 Share Posted February 4, 2007 In your linking part, try this: <?php echo '<li><h3>'; echo $upload; if(isset($upload)){ echo '<a href="individualarticle.php?f=1&blog_id=' .$blog_id. '">'; } else{ echo '<a href="individualarticle.php?f=0&blog_id=' .$blog_id. '">'; } echo $title .'</a>'; if(isset($upload)){ echo '<img src="pin.gif" />'; } echo <<<_HTML </h3> <p style="color: red; display: inline;">written by {$author} on {$date} Posted in <a href="categorypage.php?category_id={$cat}">{$cat1}</a></p> <p>{$body}</p> </li> <p><a href="individualarticle.php?blog_id={$blog_id}">read on...</a></p> _HTML; ?> Quote Link to comment Share on other sites More sharing options...
jimmi8 Posted February 5, 2007 Author Share Posted February 5, 2007 Hi thanks for the reply! No that didnt seem to work either. The $blog_id just doesnt get in to that second query string. I dont know how to fix it! I cant work it out! Quote Link to comment Share on other sites More sharing options...
chrisranjana.com Posted February 5, 2007 Share Posted February 5, 2007 can you copy the generated link and post it here. You can delete the domain name from it though. Quote Link to comment Share on other sites More sharing options...
Orio Posted February 5, 2007 Share Posted February 5, 2007 Your coding is a real mess... Try this: <?php $sql = "SELECT entries.*, categories.*, uploads.* FROM entries INNER JOIN categories ON(categories.category_id = entries.category_id) LEFT JOIN uploads ON (uploads.blog_id = entries.blog_id) ORDER BY entries.date_submitted DESC LIMIT 3"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)) { $title = $row['title']; $body = substr($row['body'],0,400); $author = $row['author_id']; $date = $row['date_submitted']; $cat = $row['category_id']; $cat1 = $row['category']; $upload = (isset($row['upload_id'])) ? $row['upload_id'] : ""; $blog_id = $row['blog_id']; echo "<li><h3>".$upload; if(!empty($upload)) echo '<a href="individualarticle.php?f=1&blog_id=' .$blog_id; else echo '<a href="individualarticle.php?f=0&blog_id=' .$blog_id; echo $title."</a>"; if(!empty($upload)) echo "<img src=\"pin.gif\" />"; echo "</h3>"; echo "<p style=\"color: red; display: inline;\">written by ".$author." on ".$date.". " echo "Posted in <a href=\"categorypage.php?category_id=".$cat."\">".$cat1."</a></p><p>".$body."</p></li>"; echo "<p><a href=\"individualarticle.php?blog_id=".$blog_id."\">read on...</a></p>"; } ?> Orio. Quote Link to comment Share on other sites More sharing options...
jimmi8 Posted February 5, 2007 Author Share Posted February 5, 2007 HI there, Thanks for the reply. Unfortunatley that code did the same thing as, essentially, it worked in exactly the same way my more messy version did. The blog_id does not get passed to a an entry that doesnt have a file. I am absolutley bewildered. I cannot work out why this is happening. Theres something intrinsically wrong with the way this script is working. Its something to do with the fact that im left joining on the uploads. Its beginning to get me down! Quote Link to comment Share on other sites More sharing options...
Orio Posted February 6, 2007 Share Posted February 6, 2007 Try changing it to this: $blog_id = urlencode(trim($row['blog_id'])); Orio. Quote Link to comment Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Author Share Posted February 6, 2007 hi, ah i dont think its that becuase the $blog_id does get though to the first query string ( if upload is set). Quote Link to comment Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Author Share Posted February 6, 2007 Hi there, No its not that unfortunatley. When i echo out $blog_id in the if else: if($upload == 0) { echo $blog_id; echo '<a href="individualarticle.php?f=1&blog_id=' .$blog_id .'">'; } else { echo $blog_id; echo '<a href="individualarticle.php?f=0&blog_id=' .$blog_id .'">'; } it only gets through if there is an upload set. I think it has to do with my query. If i change the left join to inner join everythings working fine. I cant quite work out why and its a shame because i need a left join there! Quote Link to comment Share on other sites More sharing options...
jimmi8 Posted February 6, 2007 Author Share Posted February 6, 2007 Ha solved it! the query was too ambiguous, i added this: entries.blog_id here: SELECT entries.*, categories.*, uploads.*, entries.blog_id FROM entries INNER JOIN categories ON(categories.category_id = entries.category_id) LEFT JOIN uploads ON (uploads.blog_id = entries.blog_id) ORDER BY entries.date_submitted DESC LIMIT 3 thanks for your help 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.