0

I'm trying to create a variable named $period1 by using the value of $info[per1] to fetchRow from the classes table in a MySQL database. I'm using the following code to make the MySQL call. I am connected properly, I'm able to

My code...

$info = $db->fetchRow("select * from `profiles` where `username` =?", array($logged_in));
$period1 = $db->fetchRow("select * from `classes` where `name` =?", array($info[per1]));

The following prints Web Design and is what I use to search the classes table.

<?php echo $info[per1]?>

classes table

id  name           teacher   cost   
1   Web Design     Benrud    999

The results of the echos

<?php echo $period1?>

returns: Array

<?php echo $period1[1]?>

returns: a blank

Any suggestions?
Thanks for your help!

8
  • "You're not having any luck-" how do you know? Are you getting an error? Commented May 8, 2014 at 21:51
  • @esqewm, Blank print. I'm still VERY new to php/mysql. Commented May 8, 2014 at 21:52
  • have you looked at fetch_array? php.net/manual/en/mysqli-result.fetch-array.php Commented May 8, 2014 at 21:52
  • Share any and all code relevant to the problem to help us more accurately identify your particular issue (with sensitive information redacted, i.e. passwords). There may be issues with the way you're connecting to the database or creating the database instance in the first place. Commented May 8, 2014 at 21:53
  • Just a housekeeping note: You can post your biography on your profile. There is no reason to add "Thanks for your help! -Todd, High School Teacher" to every single question you post. Commented May 8, 2014 at 21:56

1 Answer 1

1

Instead of using [0] or [2] or [3] I tried using the table column name. The following worked

<?php echo $period1[teacher]?>
Sign up to request clarification or add additional context in comments.

3 Comments

When using that method, it's better to type $period1['teacher'] or you'll get "Notice:" errors in your logs. because teacher is first seen as a constant and then guessed to be a string.
@scrowler, thank! Hopefully I'll be able to do it more frequently.
@TecBrat, thank you for the suggestion. I will make the change.

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.