|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can anyone help - I am calling a function to retrieve a mysql result set using the following lines:
$chosen_reviews = read_chosen_reviews($submenuitem,$offset); // Display the text of each review while ( $row = mysql_fetch_array($chosen_reviews) ) { // set variables to hold columns from result set $tx_alt_text=$row["tx_alt_text"]; $review_score=$row["review_score"]; $no_of_reviews=$row["no_of_reviews"]; $id_site=$row["id_site"]; $tx_site=$row["tx_site"]; $tx_url=$row["tx_url"]; $tx_url_display=$row["tx_url_display"]; $tx_review=$row["tx_review"]; $tx_rating=$row["tx_rating"]; $dt_created=$row["dt_created"]; $dt_usr_amd=$row["dt_usr_amd"]; . . . However, when I display the page, I get the following errors: Warning: Undefined index: tx_alt_text in <filename> on line <blah> Warning: Undefined index: review_score in <filename> on line <blah> Warning: Undefined index: no_of_reviews in in <filename> on line <blah> This didn't happen last week!! It doesn't even happen across all calls to this page, just in some instances, with no rhyme or reason. The only thing I have done - which I'm not sure could have had this effect - is to change some of the session entries in my php.ini file. Also, why does this problem arise when assigning these three columns to variable names and not the other columns in the table? Any help would be much appreciated. I've been headscratching for 6 days now!! |
|
#2
|
|||
|
|||
|
Which lines are those error triggered? are they triggered on the code you pasted, or is it further down?
__________________
Best Regards, Håvard Lindset |
|
#3
|
|||
|
|||
|
The errors are being triggered by the lines where I attempt to assign the result set values to their corresponding variables.
|
|
#4
|
|||
|
|||
|
hm, can you show some more code?
|
|
#5
|
|||
|
|||
|
Not sure how much more code I can show - not much left. Here is the loop which goes through the result set and displaying values in table format. The only thing that comes after this is a call to a function which shows navigation elements.
Anyway, here it is: // Display the text of each review while ( $row = mysql_fetch_array($chosen_reviews) ) { // set variables to hold columns from result set $tx_alt_text=$row["tx_alt_text"]; $review_score=$row["review_score"]; $no_of_reviews=$row["no_of_reviews"]; $id_site=$row["id_site"]; $tx_site=$row["tx_site"]; $tx_url=$row["tx_url"]; $tx_url_display=$row["tx_url_display"]; $tx_review=$row["tx_review"]; $tx_rating=$row["tx_rating"]; $dt_created=$row["dt_created"]; $dt_usr_amd=$row["dt_usr_amd"]; // If there are reader review ratings for this site....... if ($no_of_reviews > 0){ // Calculate average score $avg_score=round($review_score/$no_of_reviews); $tx_score_path='images\alt_rating_'.$avg_score.'.g if'; } echo("<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='1' bgcolor=".MAIN_TABLE.">"); // SITE NAME echo("<tr><td id='sitename'> $tx_site</td><td align='right'><img src='$tx_rating'> </td></tr>"); echo("<tr><td colspan='2'>"); echo("<table width='100%' border='0' cellspacing='0' cellpadding='0' bgcolor=".TERTIARY.">"); echo("<tr><td colspan='3'><img src='../images/space.gif' height='5px' width='1px' /></td></tr>"); echo("<tr><td> </td><td><a id='sitelink' target='_blank' href='$tx_url'>$tx_url_display</td><td> </td></tr>"); // REVIEW TEXT echo("<tr><td> </td><td id='main'>$tx_review</td><td> </td></tr>"); echo("<tr><td colspan='3'><img src='../images/space.gif' height='10px' width='1px' /></td></tr>"); // If there are reader review ratings...... if ($no_of_reviews > 0){ echo("<tr><td> </td><td><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td id='mainlabel'><b>Average reviewer rating</b>: <img src='$tx_score_path' /></td>"); echo("<td id='mainlabel'><b>Number of reviews</b>: $no_of_reviews</td></tr></table></td><td> </td></tr>"); } else { echo("<tr><td> </td><td><table cellspacing='0' cellpadding='0' border='0'><tr><td id='main'>This site has not been rated by readers yet.</td></tr></table></td><td> </td></tr>"); } // Change the status message for the review depending on whether it is new or an update // New sites will depict: 'Review Written: <date>' // Other sites will depict: 'Review Updated: <date>' if ($dt_created == $dt_usr_amd ){ echo("<tr><td> </td><td id='mainlabel'><b>Review Written:</b> $dt_created</td><td> </td></tr>"); } else { echo("<tr><td> </td><td id='mainlabel'><b>Review Updated:</b> $dt_usr_amd</td><td> </td></tr>"); } echo("<tr><td colspan='3'><img src='../images/space.gif' height='10px' width='1px' /></td></tr>"); echo("<tr><td> </td><td><a href='../reader_reviews/reader_reviews_index.php?submenuitem=$submenuitem&menuitem=$menuitem&siteid=$id_site'><img border='0' src='../images/rate.gif'></a></td><td> </td></tr>"); echo("<tr><td colspan='3'><img src='../images/space.gif' height='10px' width='1px' /></td></tr>"); echo("</td></tr></table>"); echo("</td></tr></table>"); echo("<tr><td> </td></tr>"); } Also, here's the SQL code for the read_chosen_review function: function read_chosen_reviews($submenuitem,$offset) { $chosen_reviews = @mysql_query("SELECT id_site, no_of_reviews, review_score, tx_site, tx_url, tx_url_display, id_new_flag, tx_review, tx_rating, date_format(dt_created,'%D %b %Y') AS dt_created, date_format(dt_usr_amd,'%D %b %Y') AS dt_usr_amd, tx_path, tx_alt_text FROM review WHERE id_active = 1 AND id_sub_category=$submenuitem ORDER BY dt_usr_amd DESC LIMIT $offset,".PAGE_LIMIT); return $chosen_reviews; } |
|
#6
|
|||
|
|||
|
Quote:
That error is generated by a bad array() index. So, in short, you are trying to asign your variables to an array() value that does not exist. Check your query and make sure it is retreiving the correct results......
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#7
|
|||
|
|||
|
Thanks jpenn.
This made me look at my SQL again, and although it was working fine, I decided to assign aliases to the errant fields and this solved the problem. Don't know why this would be a problem with just these columns, so I've assigned aliases to the whole result set. Cheers all for the help. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Warning: Undefined index |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|