Web Hosting Talk







View Full Version : vbulletin php code - mysql select query returning resource ids


Nullified
07-03-2004, 06:43 PM
I am trying to run the following code in a vbulletin php page:
$theuserid = "2";
$file_name = $DB_site->query("SELECT file FROM user WHERE userid = $theuserid");
$site_text = $DB_site->query("SELECT site_text FROM user WHERE userid = $theuserid");
$site_link = $DB_site->query("SELECT site_link FROM user WHERE userid = $theuserid");
$banner = "<a target=\"_blank\" title=\"$site_text\" href=\"$site_link\"><img alt=\"$site_text\" src=\"http://www.thewebsite.com/images/banners/$file_name\" width=\"468\" height=\"80\" border=\"0\"></a>";
//$DB_site->query("UPDATE user SET total=total+1 WHERE userid = $theuserid");
//$DB_site->query("UPDATE user SET impressions=impressions-1 WHERE userid = $theuserid");
print $banner;

file where userid = 2 in table "user" contains the value: 2.gif
site_text where userid = 2 in table "user" contains the value: The Alternate Text
site_link where userid = 2 in table "user" contains the value: http://www.thewebsite.com

Why is the output this?:
<a target="_blank" title="Resource id #21" href="Resource id #22"><img alt="Resource id #21" src="http://www.thewebsite.com/images/banners/Resource id #20" width="468" height="80" border="0"></a>

barrywien
07-03-2004, 07:56 PM
First of all I would suggest checking your database, to confirm that the info is not all the same as that appears to be the problem from looking at your source, it seems fine.

Nullified
07-03-2004, 07:58 PM
Originally posted by barrywien
First of all I would suggest checking your database, to confirm that the info is not all the same as that appears to be the problem from looking at your source, it seems fine.

I repeat:
file where userid = 2 in table "user" contains the value: 2.gif
site_text where userid = 2 in table "user" contains the value: The Alternate Text
site_link where userid = 2 in table "user" contains the value: http://www.thewebsite.com

I have checked my database with phpmyadmin and the values above are inserted into the fields.

barrywien
07-03-2004, 08:03 PM
Ok try replacing the code with the following:$theuserid = "2";
$filename = $DB_site->query("SELECT file FROM user WHERE userid = $theuserid");
$sitetext = $DB_site->query("SELECT site_text FROM user WHERE userid = $theuserid");
$sitelink = $DB_site->query("SELECT site_link FROM user WHERE userid = $theuserid");
$banner = "<a target=\"_blank\" title=\"$sitetext\" href=\"$sitelink\"><img alt=\"$sitetext\" src=\"http://www.thewebsite.com/images/banners/$file_name\" width=\"468\" height=\"80\" border=\"0\"></a>";
//$DB_site->query("UPDATE user SET total=total+1 WHERE userid = $theuserid");
//$DB_site->query("UPDATE user SET impressions=impressions-1 WHERE userid = $theuserid");
print $banner;I didnt mean to sound rude above, but its always best to be 100% sure with this sort of problem.

The above may work, but obviously I havnt tested it, and its 1:03AM so my eyes are closing slowly at the moment.

Nullified
07-03-2004, 08:08 PM
I didn't mean to sound rude either if I did, lol.
Sadly, that code gives me the same results. :(

I don't know what the heck is going on. This code should work fine.

nexcess.net
07-04-2004, 12:43 AM
Most queries return result sets, not individual values. I'd check the DB_site class and see if there's a version of ->query that returns a single value when there is a single column/row result. Or use the mysql_fetch_* functions on what I'm assuming is the result set returned from ->query.

Chris

Burhan
07-04-2004, 01:27 AM
I believe you need to use $DB_site->fetchrow() or something along those lines.

Nullified
07-04-2004, 07:30 AM
Call to undefined function: fetch()
Call to undefined function: fetch_row()
http://www.vbulletin.com/docs/html/main/codestandards_sql_query

nexcess.net
07-04-2004, 11:46 AM
Looks like you need:

$DB_site->query_first

based on that vb link you pasted.

Chris

Nullified
07-04-2004, 12:29 PM
Yea, I did. I also had to add some other code so the variable wasn't storing the actual db call or whatever.

igor99
07-05-2004, 10:01 PM
checking your database good idea

Nullified
07-05-2004, 10:04 PM
Originally posted by igor99
checking your database good idea Checking my database?