General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 6th, 2002, 03:59 AM
singchen singchen is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 5 singchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Warning: Undefined index

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!!

Reply With Quote
  #2  
Old November 6th, 2002, 07:53 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
Which lines are those error triggered? are they triggered on the code you pasted, or is it further down?
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #3  
Old November 6th, 2002, 07:59 AM
singchen singchen is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 5 singchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The errors are being triggered by the lines where I attempt to assign the result set values to their corresponding variables.

Reply With Quote
  #4  
Old November 6th, 2002, 08:05 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Lindset Send a message via AIM to Lindset
hm, can you show some more code?

Reply With Quote
  #5  
Old November 6th, 2002, 08:13 AM
singchen singchen is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 5 singchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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'>&nbsp;&nbsp;$tx_site</td><td align='right'><img src='$tx_rating'>&nbsp;&nbsp;</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>&nbsp;&nbsp;</td><td><a id='sitelink' target='_blank' href='$tx_url'>$tx_url_display</td><td>&nbsp;&nbsp;</td></tr>");

// REVIEW TEXT
echo("<tr><td>&nbsp;&nbsp;</td><td id='main'>$tx_review</td><td>&nbsp;&nbsp;</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>&nbsp;&nbsp;</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>&nbsp;&nbsp;</td></tr>");
} else {
echo("<tr><td>&nbsp;&nbsp;</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>&nbsp;&nbsp;</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>&nbsp;&nbsp;</td><td id='mainlabel'><b>Review Written:</b> $dt_created</td><td>&nbsp;&nbsp;</td></tr>");
} else {
echo("<tr><td>&nbsp;&nbsp;</td><td id='mainlabel'><b>Review Updated:</b> $dt_usr_amd</td><td>&nbsp;&nbsp;</td></tr>");
}

echo("<tr><td colspan='3'><img src='../images/space.gif' height='10px' width='1px' /></td></tr>");
echo("<tr><td>&nbsp;&nbsp;</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>&nbsp;&nbsp;</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>&nbsp;</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;
}

Reply With Quote
  #6  
Old November 6th, 2002, 12:05 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
Warning: Undefined index: tx_alt_text in <filename> on line <blah>

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.




Reply With Quote
  #7  
Old November 7th, 2002, 05:14 AM
singchen singchen is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 5 singchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Warning: Undefined index


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT