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
Only the first variable is passed to the rest of the script
Old 09-30-2007, 10:06 PM Only the first variable is passed to the rest of the script
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
I am running the script below, and it pulls the data based on the mysql_num_rows, and the $var1 variable. However, it does not pass any of the other variables.

Here is the script:

PHP Code:
$submission $_POST["siteurl"];
$dbh mysql_connect("localhost""username""password") or die('I cannot connect to the database because: ' mysql_error());
mysql_select_db("database");
$sql "SELECT var1, var2, var3 FROM ads WHERE url = '$submission' LIMIT 1";
$result mysql_query($sql$dbh) or die(mysql_error());
while (
$newArray mysql_fetch_array($result))
$var1 $newArray"var1" ];
$var2 $newArray"var2" ];
$var3 $newArray"var3" ];
if (
mysql_num_rows($result) < 1)
{
  echo 
"Not found";
}
else
{

  {

  }
if ( 
$var1 == "1" ) {
   echo 
"Message 1 $var2<br>$var3";
}
elseif ( 
$var1 == "3" ) {
    echo 
"Message 2 $var3";
}
elseif ( 
$var1 == "0" ) {
    echo 
"Message 3";
}
elseif ( 
$var1 == "4" ) {
    echo 
"Message 4 $var3;
}} 
This only outputs the messages, not including the echoed variables. Does anyone know what's happening here? How can I fix this?
__________________

Please login or register to view this content. Registration is FREE
neorunner is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-01-2007, 02:13 AM Re: Only the first variable is passed to the rest of the script
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If you print_r($newArray) what does it output?

And also I wonder, why all newbies use such complicated ways of debugging? It is not only easier to print_r() the whole result set but much more obvious than make lots of elseif's.
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-01-2007, 06:36 AM Re: Only the first variable is passed to the rest of the script
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
I tried print($newArray) yesterday. It outputs "Array", nothing more.
__________________

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

Last edited by neorunner; 10-01-2007 at 08:06 PM..
neorunner is offline
Reply With Quote
View Public Profile
 
Old 10-01-2007, 07:49 AM Re: Only the first variable is passed to the rest of the script
Ultra Talker

Posts: 483
Trades: 0
print_r( $newArray ) shows 'Array'?

print( $newArray ) would show 'Array', but print_r should show the items in the array... if that's what print_r shows, well...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 10-01-2007, 08:05 PM Re: Only the first variable is passed to the rest of the script
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
print_r($newArray) doesn't display anything. I guess it was print that said Array. I had already tested print $newArray, and it just said "Array". I thought you were asking me if I had tested print $newArray, so I gave the answer to that question. When I realized my mistake, I corrected this post to eliminate confusion to future readers. I apologize for not clarifying my intentions.
__________________

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

Last edited by neorunner; 10-02-2007 at 06:03 PM.. Reason: to clarify earlier edit for babosos who jump to invalid conclusions.
neorunner is offline
Reply With Quote
View Public Profile
 
Old 10-02-2007, 01:47 AM Re: Only the first variable is passed to the rest of the script
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If your $newArray is really array then print_r() won't display nothing, it would display
Code:
Array (
)
Now look what var_dump($newArray) will produce.
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-02-2007, 01:52 AM Re: Only the first variable is passed to the rest of the script
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Obviously if print_r() on array shows nothing then that array is not an array but a boolean with false value.

Moreover I found an error in your code. You do while () without curly brackets {} which means that ONLY THE FIRST operation standing after while will be executed, in your case only $var1 = $newArray[ "var1" ] will be assigned within cycle, but $var2 and $var3 will be assigned values of the LAST record in result set. This does not matter when you select only 1 record, but if you select more you will get not what you expected.
__________________

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

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-02-2007, 07:25 AM Re: Only the first variable is passed to the rest of the script
Ultra Talker

Posts: 483
Trades: 0
mtishetsky is right... good work mate! If that doesn't fix it entirely it will at least get you pretty close.

Also I notice that at the very end up your code you forget to close the quote on:
echo "Message 4 $var3;

Might I also add that when comparing variables to numbers, you shouldn't put those numbers in quotes. Technically you are making PHP compare the variable to a string... it converts that string to a number but it doesn't always work correctly.

Finally, it's really been niggling me that you edited your second post in this thread. It's one thing to change the spelling or add information, but when you go back and change what you said you did to what you actually did do, after being called on it, is really dodgy. Removing the stuff about being called a noob is up to you, but if you weren't called on that simple thing in the first place I wonder if you would have removed it at all...

Anyway, mtishetsky, good work!
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 10-02-2007, 05:51 PM Re: Only the first variable is passed to the rest of the script
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
I made the correction to remove any confusion for anyone reading after I realized my mistake. I had tried "print", not "print_r", but I was not in a place where I had access to test "print_r" to verify. So, I posted the results as I thought they were at the time. When I realized my mistake, I fixed my earlier post, and mentioned my misunderstanding in the next post. Perhaps I should have been more clear about my intentions, but it is hardly worthy of being called "dodgy".

I sent you a private message asking you to remove this rude post, but you have obviously ignored me. So, I have to clarify the misunderstand so future readers will not be misguided by your slanderous remarks.
HTML Code:
</rant>
__________________

Please login or register to view this content. Registration is FREE
neorunner is offline
Reply With Quote
View Public Profile
 
Old 10-02-2007, 08:27 PM Re: Only the first variable is passed to the rest of the script
Ultra Talker

Posts: 483
Trades: 0
Quote:
I sent you a private message asking you to remove this rude post, but you have obviously ignored me.
No, I just didn't really have the time during the less than two hours you gave me to reply at all. God help me if I was in a totally different timezone and asleep!

I'm not looking to get into an argument. My post was about two things: firstly, I understand that if you realise you make a mistake you go and fix your post. But don't do it after replies have been made. Our replies are in response to your original post: it doesn't help new readers to follow things when they see you say one thing then they see our replies to the original text.

So we disagree: you think that the further up the thread you can correct yourself the better. I think that it just confuses people when they see bizarre replies (and those replies make ME look stupid).

I guess part of my response was related to the, what I perceived to be, "you take that back I'm not a noob" reply you gave to begin with... and then removed once you were made aware of the simple mistake you had made. Unfortunately I shift-deleted the email that had the original text in it, but anyway. We all make mistakes but the attitude, I thought, was fairly offensive and so when you totally edited it out after being shown some basic mistakes, well... I thought that was 'dodgy'.

Sorry if I offended you.

I hope the other answers helped you to resolve your issue...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Only the first variable is passed to the rest of the script
 

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.30939 seconds with 12 queries