View Full Version : Would this work please....


Phillip
06-21-2006, 09:42 AM
Ok, i'm building a news system the idea being they can click a link and it will take them to a seperate page which shows the news and the comments.
I plan to have a readfull.php and then have it say the id like this:

www.mywebsite.com/news/showfull.php?id=5

and then in the readfull file have:
$query = "SELECT news FROM where id='$id'";

so here is the script for showing the latest news:

<?php # Show_news.php

// Make the connection.
$dbc = mysql_connect ('localhost', 'phillk_Phillip', 'password', 'phillk_profiles') OR die ('Could not connect to MYSQL: ' . mysql_connect_error());


mysql_select_db("phillk_news",$dbc);

// Make the query.
$query = "SELECT newstitle from WHERE newstitle='$nt'";
$result = mysql_query ($query) or trigger_error ("Query: $query\n<br />Mysql error: " . mysql_error());

if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array ($query)) {
echo "<a href="/news/read_all.php?$row['id']>$row['link_desc']</a>
}

} else { // No recoreds returned.
echo '<p>There is no current news to display!';
}
// Free the result and close the connection.
/*mysql_free_result($result);
mysql_close($dbc); */
?>


is that going to work? thanks

Douglas
06-21-2006, 03:09 PM
No it won't:

$dbc = mysql_connect ('localhost', 'phillk_Phillip', 'password', 'phillk_profiles') OR die ('Could not connect to MYSQL: ' . mysql_connect_error());

That should be:

mysql_connect ('localhost', 'phillk_Phillip', 'password', 'phillk_profiles') or die('Could not connect to MYSQL: ' . mysql_error());

You didn't define a table name:

$query = "SELECT newstitle from WHERE newstitle='$nt'";

That should be something like this:

$query = "SELECT * FROM table WHERE newstitle='$nt'";

And this:

while ($row = mysql_fetch_array ($query)) {
echo "<a href="/news/read_all.php?$row['id']>$row['link_desc']</a>
}

Should be:

while ($row = mysql_fetch_array ($query)) {
echo "<a href=\"/news/read_all.php?".$row['id'].">".$row['link_desc']."</a>";
}

Then it should work.

Raphael
06-22-2006, 07:12 PM
Douglas, ya missed out another escape ;)

Last line:

echo "<a href=\"/news/read_all.php?".$row['id'].">".$row['link_desc']."</a>";

should be:

echo "<a href=\"/news/read_all.php?".$row['id']."\">".$row['link_desc']."</a>";

Although for a properly formed GET request, Phillip needs an actual variable in there, otherwise he's going to have a harder time getting the id out...

So, something like:

echo "<a href=\"/news/read_all.php?rowId=".$row['id']."\">".$row['link_desc']."</a>";