0

I am trying to get a specific square in a mysql table. Here is what I have so far.

$sql = "select Saturdaymorning From schedule where username like '%$user%';";
$stmt = $db->prepare("select Saturdaymorning From schedule where username like '%$user%';");
$stmt = $db->exec($sql)

$sql1 = "select Saturdayafternoon From schedule where username like '%$user%';";
$stmt1 = $db->prepare("select Saturdayafternoon From schedule where username like '%$user%';");
$stmt1 = $db->exec($sql1)

I am able to get the first one to work but the second gets a buffer error. How could one run multiple queries at once. I do not understand the "fetchall()" command or how it works. Thanks

[EDIT] I have to call them apart because I use them in if statements akin to

if($sql = "yes"){ satmorn = "Saturday Morning"} 

and so on.

4
  • whats the use of havin it prepared when you just injected the variables directly in the statement, use them placeholders, then bind the values. Commented Jan 20, 2016 at 4:06
  • Use Prepared Statements with binding parameters Commented Jan 20, 2016 at 4:22
  • @Ghost how would I do this? Commented Jan 20, 2016 at 4:22
  • @MathMXC its already in the manual there's an example of how to use binding including the fetch Commented Jan 20, 2016 at 4:25

1 Answer 1

1

Not sure about PHP but I really don't see why you need to run multiple queries here when you are selecting from same table. You can modify your query to combine both statement be

select Saturdaymorning,
Saturdayafternoon
From schedule 
where username like '%$user%'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.