Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Another issue with my loops :(
Old 11-21-2010, 05:28 PM Another issue with my loops :(
Skilled Talker

Posts: 77
Name: adam
Location: UK
Trades: 0
Hi sorry about this, I have another issue with my script.

I am getting the following errors.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\prototype2\control_panel.php on line 73

Notice: Undefined variable: contact in C:\wamp\www\prototype2\control_panel.php on line 84

here is the code.

PHP Code:
$sql="SELECT * FROM 'numbers' WHERE 'id' = '".$useridvar."'";
        
$result=mysql_query($sql);
            while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
                {
                    
$contact $row["number"];
                    
$privacy_mode $row["privacy_mode"];
                    
$personal_number $row["personal_number"];
                }
        echo 
'<div id="control_panel_info">';
          echo 
'<table width="200" border="0" cellpadding="4">';
            echo 
'<tr>';
              echo 
'<td id="control_left_td">Your Current Contact :</td>';
              echo 
'<td>'.$contact.'</td>';
              
?> 
The errors occur on

PHP Code:
    while ($row mysql_fetch_array($resultMYSQL_ASSOC)) 
and

PHP Code:
              echo '<td>'.$contact.'</td>';
              
?> 
however I think the last error occurs because I have noticed my while loop does not run. therefore the contact var is not going to have anything in it until the loop is ran. My userid session is set because at the top of the page I have a echo line which tells me the userid which is set from the database.

Thanks.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
mintuz is offline
Reply With Quote
View Public Profile Visit mintuz's homepage!
 
 
Register now for full access!
Old 11-21-2010, 05:56 PM Re: Another issue with my loops :(
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The problem is here:
PHP Code:
$sql="SELECT * FROM 'numbers' WHERE 'id' = '".$useridvar."'"
Quotes are used for values, backticks are used for tables and columns. In this case you don't even need to use backticks.

Try:
PHP Code:
$sql="SELECT * FROM numbers WHERE id = '".$useridvar."'"
You may want to just skip concatenating all together since you are already using double quotes:
PHP Code:
$sql="SELECT * FROM numbers WHERE id = '$useridvar';"
Also, assuming the id is unique, there is no reason to use a loop since there should only be one row. Technically it will work either way, but it is clearer to use if instead of while.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-21-2010 at 06:03 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Another issue with my loops :(
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25442 seconds with 12 queries