Page 2 of 2
Re: understanding this PHP code
Posted: Fri Feb 15, 2013 5:26 pm
by jonnyfortis
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?
Re: understanding this PHP code
Posted: Fri Feb 15, 2013 5:54 pm
by requinix
Not your code. The query. Which is in your code yes but I do mean the query itself.
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"));
That. Echo out $query2 and try running it yourself in MySQL (like with a console or phpMyAdmin).
Re: understanding this PHP code
Posted: Fri Feb 15, 2013 10:33 pm
by Christopher
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>
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.
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);
}
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 4:59 am
by jonnyfortis
$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);
}
the results in the source code are
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)){
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 10:23 am
by Christopher
"mysql_errno(): supplied argument is not a valid MySQL-Link resource" means that you do not have a connection to the database.
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 11:05 am
by jonnyfortis
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?
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 11:12 am
by Christopher
It the connection for $query or $query2?
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 11:58 am
by jonnyfortis
It the connection for $query or $query2?
that shown connection is at the top of the page so thought that would be for all querys
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 5:36 pm
by Christopher
Sorry $query2 is the SQL (calling it $sql would be clearer). I don't see anywhere in this code where you call mysql_connnect().
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 6:04 pm
by requinix
Christopher wrote:"mysql_errno(): supplied argument is not a valid MySQL-Link resource" means that you do not have a connection to the database.
It could also mean he didn't pass in the right variable.
Re: understanding this PHP code
Posted: Sat Feb 16, 2013 8:11 pm
by Christopher
requinix wrote:It could also mean he didn't pass in the right variable.
Definitely didn't! That variable is the string with the SQL statement! It would be great to have variables like $sql and $result.