understanding this PHP code
Moderator: General Moderators
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: understanding this PHP code
ok, this is what i dont understand with the code, in respect to what part of the code is calling the tables and what is being associated with other parts of the code
does that make sense?
does that make sense?
Re: understanding this PHP code
Not your code. The query. Which is in your code yes but I do mean the query itself.
That. Echo out $query2 and try running it yourself in MySQL (like with a console or phpMyAdmin).
Code: Select all
$query2 = sprintf("
SELECT DISTINCT
stock.StockID, size.Size
FROM
beauProd AS prod
LEFT JOIN beauStock AS stock ON prod.ID = stock.ID
LEFT JOIN beauSizeList AS size ON stock.SizeID = size.SizeID
WHERE
prod.ID = '%s' AND stock.Stock > 0
ORDER BY
size.SizeID ASC", GetSQLValueString($var1_Recordset1, "int"));- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: understanding this PHP code
Not much help after the fact. I recommend wrapping the code after a query with error checking. The error message from the query will help tell you what is going wrong.jonnyfortis wrote:Code: Select all
<option value="Select Size">Select Size</option> <br /> <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>E:\Domains\b\beau.com\user\htdocs\SS13\product-description.php</b> on line <b>338</b><br /> </select>
Code: Select all
$results2 = mysql_query($query2);
if (!mysql_errno($query2)) {
while($row2 = mysql_fetch_array($results2)){
?>
<option value="<?php echo $row2['Size']; ?>"><?php echo $row2['Size']; ?></option>
<?php
}
} else {
echo "DB ERROR: " . mysql_error($query2);
}
(#10850)
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: understanding this PHP code
the results in the source code are$results2 = mysql_query($query2);
if (!mysql_errno($query2)) {
while($row2 = mysql_fetch_array($results2)){
?>
<option value="<?php echo $row2['Size']; ?>"><?php echo $row2['Size']; ?></option>
<?php
}
} else {
echo "DB ERROR: " . mysql_error($query2);
}
Code: Select all
<option value="Select Size">Select Size</option>
<br />
<b>Warning</b>: mysql_errno(): supplied argument is not a valid MySQL-Link resource in <b>E:\Domains\b\beau.com\user\htdocs\SS13\product-description.php</b> on line <b>338</b><br />
<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>E:\Domains\b\beau.com\user\htdocs\SS13\product-description.php</b> on line <b>339</b><br />
</select>line 338 and 339 of the code are
Code: Select all
if (!mysql_errno($query2)) {
while($row2 = mysql_fetch_array($results2)){- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: understanding this PHP code
"mysql_errno(): supplied argument is not a valid MySQL-Link resource" means that you do not have a connection to the database.
(#10850)
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: understanding this PHP code
hmm? but i do have a connection for the rest of the page,
<?php require_once('../Connections/beau.php'); ?>
do i need to specify the connection again for the other query?
<?php require_once('../Connections/beau.php'); ?>
do i need to specify the connection again for the other query?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: understanding this PHP code
that shown connection is at the top of the page so thought that would be for all querysIt the connection for $query or $query2?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: understanding this PHP code
Sorry $query2 is the SQL (calling it $sql would be clearer). I don't see anywhere in this code where you call mysql_connnect().
(#10850)
Re: understanding this PHP code
It could also mean he didn't pass in the right variable.Christopher wrote:"mysql_errno(): supplied argument is not a valid MySQL-Link resource" means that you do not have a connection to the database.
Code: Select all
if (!mysql_errno($query2)) {- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: understanding this PHP code
Definitely didn't! That variable is the string with the SQL statement! It would be great to have variables like $sql and $result.requinix wrote:It could also mean he didn't pass in the right variable.Code: Select all
if (!mysql_errno($query2)) {
(#10850)