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
Old 12-23-2009, 05:56 AM While loop issue.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi me again, im starting to get VERY annoyed with my script.

I have the below: ( Snippet of offending code )

Basically it should do this:
- at the top, it does a while from the restult of a main sql query ( this works )
- It then (inside the while) does anyother sql query to see if that row is already in the DB )
- If it isnt, then it should insert it.
- If it is, Then do nothing.

Problem:
I get the output from the echo VRFname bit but the internal while doesnt seem to happen.

It doesnt echo "doing while " or the Interting echo or even the This vrf is already .. echo.

It just doesnt look like the while inside the while is happening...

Any thoughts?
( Its early and my brain is dead )

Code:

while($row = mssql_fetch_array($result))
{


$vrf = $row["VRF"];
$rd = $row["RD"];

  echo " VRFname: " . $vrf;
  echo "\n";
  echo "     RouteD: " . $rd;
  echo "\n";


$lquery = "select rd from vrf where rd = '$rd'";
$lresult = mysql_query($lquery);

while($lrow = mysql_fetch_array($lresult))
{
echo "Doing while \n";
$lrd = $lrow['rd'];

if ($lrd != "") {
echo "Inserting VRF as this didnt exist \n";

mysql_query("INSERT INTO vrf
(vrf, rd, lingertime) VALUES('$vrf', '$rd', '3' ) ")
or die(mysql_error());

// if rd
}else{
echo "This VRF is already in the table \n";
}
// Internal while mysql loop
}
//End main while 
}


//close the connection
mssql_close($dbhandle);

__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 12-23-2009, 06:09 AM Re: While loop issue.
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Then it's most likely beacuse the query didn't return any results. That is, $lresult has zero rows. Make sure the $rd variable is correct and try echoing the number of returned rows, with mysql_num_rows() for example.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-23-2009, 06:13 AM Re: While loop issue.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Well thats the thing.
Ive put echos in the while and before it.

NONE of them are being echoed.

So the while itself isnt happening.

theres a echo at the start, and one eitherside of the else.. Yet still they dont actually happen.

If the query returned 0 rows then it should still do something ( as per the i else )

Code:
while($lrow = mysql_fetch_array($lresult))
{
echo "Doing while \n";
$lrd = $lrow['rd'];

if ($lrd != "") {
echo "Inserting VRF as this didnt exist \n";

mysql_query("INSERT INTO vrf
(vrf, rd, lingertime) VALUES('$vrf', '$rd', '3' ) ")
or die(mysql_error());

// if rd
}else{
echo "This VRF is already in the table \n";
}
// Internal while mysql loop
}
__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 12-23-2009, 06:58 AM Re: While loop issue.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ah ha,
Ive fixed it.

The issue was *because* i had a while inside a while.
And the data was getting crossed mixed.


Instead of a while, i now just use $row = mysql_fetch_array($data);

and use that, But not whiling through it all.

I dont know why i even thought that would work?

I blame xmas.
__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 12-23-2009, 09:48 AM Re: While loop issue.
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Well, it should still work with a while inside of another while. You can have as many loops inside of each other as you want.
Just having
PHP Code:
$row mysql_fetch_array($data); 
is the same thing as
PHP Code:
while ($row mysql_fetch_array($data)) {
   
// ...

if there is only one row returned.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-23-2009, 09:54 AM Re: While loop issue.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
yeah im sure it does work.

Its just my logic was fubar'd and i didnt need a while as that would break it..

ty
__________________

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


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to While loop issue.
 

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