PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
billythekid
Forum Newbie
Posts: 8 Joined: Tue Dec 09, 2014 11:12 pm
Post
by billythekid » Sun Dec 21, 2014 6:09 pm
please take a look at my code and help me figure out why im getting the following error:
something along the lines of "my_sql_fetch_array expects parameter 1 to be source"
///////begin code
Code: Select all
$ordernumber = $_POST['ordernumber'];
$dbname = "bob_orders";
$pdo = new PDO( "mysql:dbname=$dbname;host=$host" , $user , $password);
$sql= "SELECT * FROM invoices WHERE OrderNumber= $ordernumber";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':OrderNumber', $ordernumber, PDO::PARAM_INT);
$stmt->execute();
echo "<table align=\"center\"><tr><td>Order Number</td><td>First Name</td><td>Order Status</td></tr>";
if($pdo){
while($row = mysql_fetch_array($sql))
{
echo "<tr><td>";
echo $row['OrderNumber'];
echo "</td><td>";
echo $row['FirstMiddle'];
echo "</td><td>";
echo $row['Status'];
echo "</td></tr>";
}
echo "</table><br><br><br><br>";
}
/////////end code
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Dec 21, 2014 6:23 pm
You're mixing PDO with the mysql_* functions. They're two different things. You need to pick one and use just that. (PDO would be best.)
$stmt is a
PDOStatement which has its own way of getting rows from the query. For example,
->fetch .
billythekid
Forum Newbie
Posts: 8 Joined: Tue Dec 09, 2014 11:12 pm
Post
by billythekid » Sun Dec 21, 2014 7:36 pm
thanks. i got it working now with the fetch:assoc query.
if only i could figure out how to make it display as a table instead of a line of text that says "array->[OrderNumber] 'value' " etc. i would be set
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Dec 21, 2014 9:47 pm
But... you are using a table. Got the <table> and everything.
billythekid
Forum Newbie
Posts: 8 Joined: Tue Dec 09, 2014 11:12 pm
Post
by billythekid » Sun Dec 21, 2014 10:03 pm
Oh, sorry I should've been more clear.
I rewrote the entire query just to perform the fetch function, deleted the table part. Are you saying I can simply add the table part back and it will display properly even with a fetch query instead of the query I was using before?
I assume I will need a foreach or a while loop
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Dec 22, 2014 12:14 am
Maybe not "simply", depends what you did to the code of course.
Try adding it back in. If you have problems, post the code and describe what it's doing wrong.