URL Variables

Hi again,

If you are asking how long I’ve been doing PHP: I’ve been doing it for a little over 10 years now. It’s easy to miss the small things because when we see an error, our first thought is that it must be a big error. However, most of the time it’s the small things that we overlook that gets us, like not encapsulating PHP, forgetting to terminate a line with a semicolon, etc. The more you are exposed to errors, the better you’ll be in the future as you will start knowing how and what to look for when finding the fix to errors.

Now as far as the error you get when you hit submit, is it your error that you are expecting or is it a PHP error? If it is on your end and is working as intended, I hope I was able to answer all of your questions and was able to point you in the right direction to all of your issues brought up in this forum topic. I hope to be of more assistance in the future as it presents itself. Good luck on your scripting and we are always here 24/7 on www.phphelp.net. Have a nice day… :smiley:

Heya,

Thanks for that. I think I’ve been trying to learn for about 2weeks now and every time I feel I;ve accomplished something it creates another 10questions i’m unsure about. I guess its a quick learning curve tho!

Its not an error I have written into the script. I did notice that it still doesn’t add the P_Id to the url. could that have something to do with the error? I now get www.banterdonkey.com/comment.php?storyid=

Many thanks,

Sam

I replaced this

with

and the url now appears as www.banterdonkey.com/storyid=1 or whatever number the story is.

However i still get the same error message. Does that mean its something with my comment.php script rather than my read more.php script?

Sam

Got it!

the form action should have been comment.php not comments.php - idiot!

Thank you for all your help!

Sam

Hi again,

Don’t hate yourself for that error as my code that you used had comments.php instead of comment.php. It was a mistake on my part but you kind of understand how errors so small can be seen as so big. Like I said before I look forward to assisting you in the future and good luck in your coding future.

Cheers!

Back again!

On my home page I would like to include a simple count function that shows howmany comments each individual story has attached to it.

This is what i have come up with.

[code]

BanterDonkey | The Source of Guernsey Banter
Home
Submit
Register
Contact
<?php $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("banterdonkey") or die(mysql_error()); // Assuming you've already connected to your database: $result = mysql_query("SELECT * FROM banter ORDER BY P_Id ASC"); // Replace "table_name" with the name of your table. // And replace "row_primary" with the name of the column you marked as the primary key. $count= mysql_query("SELECT COUNT(parent) FROM comments WHERE parent='$row['P_Id']'"); while ($row = mysql_fetch_array($result)) { echo "
"; echo "
{$row['P_Id']}
"; // Replace "column_one" with the name of your first column. echo "
{$row['story']}
"; // Replace "column_two" with the name of your second column. echo "
{$row['screen_name']}
"; // Replace "column_three" with the name of your third column. echo "
{$count}
"; // Replace "column_three" with the name of your third column. echo "
"; // Your submit button. (adds one to each row) echo "
"; } mysql_close($con); ?> [/code]

I thought this would be right but its not working. The P_Id of the story is the same as the parent for the comments table.

Many thanks,

Sam

Hi again,

I’m not really that well endowed with javascript, but you can use PHP and MySQL to do the same thing. Use the following query syntax:

[php]“SELECT count(*) AS ‘n’ FROM

WHERE storyid=’$row[storyid]’”[/php]

When you run the query and put the result in an array, the array (let’s call that array result) will contain the total number of rows in the table.

If there are 10 comments for a storyid, $result[‘n’] would contain 10. Hope this helps.

That wasnt to dissimilar from what i had except I had an extra pair of ’ which was causing a syntax error. This seems to be working correctly, the only issue i’m having now is everystory is appearing as having 1 comment. Most currently have 0 and a few have 2 or 3.

[php]<?php
$con = mysql_connect(“host”,“user”,“password”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“database”) or die(mysql_error());

// Assuming you’ve already connected to your database:
$result = mysql_query(“SELECT * FROM banter ORDER BY P_Id ASC”);
// Replace “table_name” with the name of your table.
// And replace “row_primary” with the name of the column you marked as the primary key.

$count= mysql_query(“SELECT count(*) AS ‘n’ FROM comments WHERE parent=’$row[P_Id]’”);
$result2=mysql_fetch_array($count);

while ($row = mysql_fetch_array($result)) {
echo “

”;
echo “
{$row[‘P_Id’]}
”; // Replace “column_one” with the name of your first column.
echo “
{$row[‘story’]}
”; // Replace “column_two” with the name of your second column.
echo “
{$row[‘screen_name’]}
”; // Replace “column_three” with the name of your third column.
echo “
{$result2[‘n’]}
”; // Replace “column_three” with the name of your third column.
echo “
Read more
”; // Your submit button. (adds one to each row)
echo “”;
}

mysql_close($con);
?>[/php]

Any suggestions?

Thanks,

Sam

Hi again,

Try putting the count query inside the while loop. As it is right now, the count query only happens once outside the loop and that’s why you are getting the same value. Once you put the second query inside the while loop, you should begin to see the results you are looking for.

Hope that helps.

Absolute Genius!

I need to learn all this is there a good book you could recommend?

Many Thanks,

Sam

Sponsor our Newsletter | Privacy Policy | Terms of Service