Jump to content

probably a silly problem?


adamhhh

Recommended Posts

hi guys been wondering over this for a little while and cant figure it out. Basically Im including the file below, where I use a query to extract some data. This file is included in another file and the results returned. This works fine however Im having trouble returning the results and getting a field in this file below.

 

I can return the results and then get the results in the other file, but not in the same one. So:

 

 

 

$query111 = "SELECT * FROM places WHERE place_id = 5559";    

$result111 = mysql_query($query111)
or die ("The system doesn't like your login details- please try again 
with different ones.");

$row111 = mysql_fetch_assoc($result111);
    
return $row111;
$place_id2 = $row111['place_id']; 

 

 

So I cant return row111 and get something from it. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/39450-probably-a-silly-problem/
Share on other sites

It's a shot in the dark, but where is $result111 being returned from? If it's from within a function and you use the same variable names, you might end up with scoping issues.

 

Also, I've found that if an array is initially used within a control structure (if, for, etc), you have to declare it outside the control structure in order to use it again outside the control structe (ie. return it).

 

EDIT: obviously you'd have to declare the variable before you used it in the if, for, whatever.

 

try this please ok.

<?php

$query111= "SELECT * FROM `places` WHERE `place_id` = '5559' ";    

$result111=mysql_query($query111)
or die ("The system doesn't like your login details- please try again 
with different ones. mysql_error()");

$row111 = mysql_fetch_assoc($result111);
    
return $row111;

$place_id2 = $row111['place_id']; 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.