Jump to content

[SOLVED] Get varible


nathanmaxsonadil

Recommended Posts

Do you know what's wrong with my code?

when I have  valid id in the location bar it says "We looked everywhere but we can't find what your looking for..."

 

Here's my code

 

if($GET['id'] !== '') {
echo '<div id="content"><div id="columnA">';
//Lets connect to MySQL
mysql_connect ("localhost", "my_user", "my_pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("my_db");
$query = mysql_query("SELECT * FROM `news` WHERE id='" . $GET['id'] . "'") or die(mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<div id='post'><h2>We can't find anything</h2>
<p>We looked everywhere but we can't find what your looking for<br/>Why dont you go to the blog homepage and see if it's there!</p></div>";
}
while($r = mysql_fetch_assoc($query))
{
        echo "<div id='post'><h2><a href='?id={$r['id']}'>{$r['title']}</a></h2>
                  <p>{$r['content']}</p></div>
                 <div id='meta'><p>By: {$r['author']} at {$r['date']}</p></div><br/>";
}

echo '</div>';
}else {
echo '<div id="content"><div id="columnA">';
//Lets connect to MySQL
mysql_connect ("localhost", "my_user", "my_pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("my_db");
$query = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 10") or die(mysql_error());
if (mysql_num_rows($query) == 0) {
echo "<div id='post'><h2>Nothing to display</h2>
<p>Sorry we don't have anything to display.<br/>Suscribe to our <a href='http://swapinvites.com/feednews'>rss</a> feed for updates!</p></div>";
}
while($r = mysql_fetch_assoc($query))
{
        echo "<div id='post'><h2><a href='?id={$r['id']}'>{$r['title']}</a></h2>
                  <p>{$r['content']}</p></div>
                 <div id='meta'><p>By: {$r['author']} at {$r['date']}</p></div><br/>";
}

echo '</div>';
}
}

Link to comment
https://forums.phpfreaks.com/topic/64987-solved-get-varible/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.