blarg
blarg

Reputation: 3893

Display MYSQL resource pointer as hyperlink in PHP

I'm trying to display the result of an MYSQL select count as a hyperlink in PHP.

When I output the result as plain text it works with this line.

Print"<th>Meeting count:</th> <td>".mysql_result($result2,0) . "</td> ";

But when I try it in a hyperlink it either comes up with the resource pointer ID or completely blank.

Here's the line I'm trying using mysql_fetch_assoc at the moment.

$rec = mysql_fetch_assoc($result2,0);
Print "<td><a href='userprofile3.php?profileID=$profileID'>$rec</a></td>";

I have a feeling I'm missing a character in this line

The profileID is generated from my other query

$profileID = $info['userID']; 

And here is the query where the count is generated

$result2 = mysql_query("select count(meetingCode) FROM meeting where meeting.userID = $profileID AND SUBSTRING( meetingCode, 5, 2 ) BETWEEN 12 AND 22 AND SUBSTRING( meetingCode, 7, 2 ) BETWEEN 1 AND 12 AND SUBSTRING( meetingCode, 9, 2 ) BETWEEN 01 AND 31");

Upvotes: 2

Views: 145

Answers (2)

Martin Sommervold
Martin Sommervold

Reputation: 152

mysql_fetch_assoc returns an array, which you cannot output directly. Depending on your query, you want to do $rec['columnName'], e.g. SELECT name FROM users would give you $rec['name'].

Upvotes: 0

S&#233;bastien Renauld
S&#233;bastien Renauld

Reputation: 19672

You're fetching an associative array using mysql_fetch_assoc() (which, by the way, only takes one parameter! You're running without PHP errors, so you probably didn't see it). This is NOT a string/string-convertible variable.

However, what it does have is the name of all the columns in the format $rec['columnName']. I can't correct your code as I do not know the name of your columns, but it should be simple for you to edit your code. One thing, though - if you don't concatenate, you'lll need to use {$rec['columnName']}.

One last thing. All mysql functions have been deprecated in favour of PDO and MySQLi. Switch to them.

Upvotes: 1

Related Questions