0

I want to query an id value from a table, based on the stopname that user inputs - Table:

id_stops stopname

1 Eastgate

2 CityCenter

and store the value in a variable so it can be used in another query

The second query runs when the id_stop = '' value is an int, the problem is storing the first query value so it can be used instead of typing the int.

$req = $conn->prepare("SELECT id_stop FROM stops WHERE stopname = :value");
$req->execute(array('value' => $value1));
$result2 = mysql_query($reg);
$value = mysql_fetch_assoc($result2,0);    
echo $value;


$stmt = $conn->prepare("SELECT id_stop, scheduletime FROM schedule 
WHERE scheduletime >= '$time' AND  id_stop = '$value' 
ORDER BY scheduletime DESC LIMIT 2;");

$stmt->execute();
camnesia
  • 2,143
  • 20
  • 26
  • I finally managed to find a solution. I combined the 2 queries and added an INNER JOIN to connect tables so two queries would not be necessary. To anyone interested in the solution: SELECT stops.stopname, schedule.scheduletime FROM schedule INNER JOIN stops ON schedule.id_stop=stops.id_stop WHERE stops.stopname = '$value1' ORDER BY scheduletime DESC; – camnesia May 14 '16 at 23:25
  • I was writting a right answer for you anyway, but Fred -ii- likes A LOT to mark questions as duplicate, even when they are just similar... I guess that marking gives you some easy and fast reputation points or something.... – nanocv May 14 '16 at 23:29
  • 1
    Thank you for taking the time :) @nanocv – camnesia May 14 '16 at 23:33

0 Answers0