Jump to content

[SOLVED] Unpacking an array results negative


GreenUser

Recommended Posts

Hi all, currently line 30 is not producing anything.  The results are the same if I use 'echo $avgrow->id;'

 

PHP Notice:  Undefined index:  id in

C:\\Program Files\\Apache\\htdocs\\ratemydate\\percent.php on line 6

 

PHP Notice:  Trying to get property of non-object in C:\\ProgramFiles\\Apache\\htdocs\\ratemydate\\percent.php on line 30

 

 

I played around for a while with the sql and in phpmyadmin I do get results I want, I just need to get them to display, not sure what I am doing wrong.

 

<?php

require("config.php");
require("functions.php");

if(pf_check_number($_GET['id']) == TRUE) {
$validid = $_GET['id'];
}
else {
$validid = 21;
}

require("header.php");

$sql = "SELECT * FROM stories WHERE id = " . $validid . ";";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

echo "<h1>" . $row['location'] . "</h1>";
echo nl2br($row['body']);

$avgsql = "SELECT SUM(fun + soh + con + sma + sex + hyg + mes) FROM stories WHERE id = " . $validid . ";";
$avgresult = mysql_query($avgsql);
$avgrow = mysql_fetch_array($avgresult);

echo "<p>";
echo "<strong>Rating</strong>: ";


echo $avgrow['id'];

echo "</p>";

require("footer.php");

?>

AS is used to create aliases in MySQL.  You basically need to create an alias for any function returns unless you want to use the numerically indexed array.  Also, aliases are good for something like:

 

SELECT u.userid AS uid FROM users as u, friends as f WHERE f.userid = $id AND f.friendid = u.userid;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.