Jump to content

var_dump giving me a bool(false), but I'm not sure why...


Recommended Posts

It's a WordPress site, but this still seems more like a PHP/MySQL issue rather than a WordPress issue. 

 

I'm trying to match Images (ngp.pid) tags (tr.object_id) that share the same ID's.  The Images matched have to then share the same ID as $wp_tagID, which the Page gets based on whatever link my user clicks.  From there I want to print what I have to the screen. 

 

Here is the test screen:

http://hoosierhoopsreport.com/tag/Michael-Volovic/ 

(All the information above the HR is from a database, linked to $wp_tagID, so I know that part of it is working.)

 

Clicking on his link, carries a $wp_tagID of 677.  When I test my query in my MySQL program and just use 677 (as $wp_tagID) it works.  I get five images that share the same link of this basketball player. 

 

The second var_dump is producing a false result on the actual page.  Not sure why. 

 

 


$qImage = '
SELECT * FROM wp_terms AS t
JOIN wp_ngg_gallery AS ngg
JOIN wp_term_taxonomy AS tt
JOIN wp_term_relationships AS tr
JOIN wp_ngg_pictures AS ngp
WHERE t.term_id = tt.term_id 
AND ngg.gid = ngp.galleryid
AND tt.term_taxonomy_id = tr.term_taxonomy_id
AND tr.object_id = ngp.pid
AND tt.taxonomy = "ngg_tag"
AND t.term_id = "$wp_tagID"
LIMIT 5';


//	AND t.term_id = "$wp_tagID"

$pImage = mysql_query($qImage);
while($image = mysql_fetch_assoc($pImage)) {

foreach ($image as $images) {

echo '<img src="http://hoosierhoopsreport.com'. $images['path'] .'/'. $images['filename'] .'>';
	}
}

var_dump($wp_tagID);
var_dump($image);


It is my second usage of mysql_fetch_assoc in the file.  I'm a tweaker, not a coder.  *shocking, right?  :D*

 

I've never really gotten a grasp of which function to use after my queries, so I basically just use that one.  Once I was told to "reset the pointer" on another issue awhile ago.  Is that my issue now? 

It shouldn't matter, as you've given it a new result resource.

 

The function will always return FALSE after it's been looped through, or if there are no rows returned.

 

<?php

mysql_connect('localhost','root','');
mysql_select_db('db');

echo '<h3>Bunch of results</h3>';
$res = mysql_query('SELECT * FROM events');
while( $row = mysql_fetch_assoc($res) ) {
var_dump($row);
echo '<br>';
}
echo 'End: ';
var_dump($row);

echo '<h3>One result</h3>';
$res = mysql_query('SELECT * FROM events WHERE id = 1');
while( $row = mysql_fetch_assoc($res) ) {
var_dump($row);
echo '<br>';
}
echo 'End: ';
var_dump($row);

echo '<h3>No results</h3>';
$res = mysql_query('SELECT * FROM events WHERE id = -1');
while( $row = mysql_fetch_assoc($res) ) {
var_dump($row);
echo '<br>';
}
echo 'End: ';
var_dump($row);

?>

 

----------------------
Bunch of results
----------------------

array
  'id' => string '1' (length=1)
  'date' => string '2012-04-27 00:00:00' (length=19)
  'source_id' => string '1' (length=1)

array
  'id' => string '2' (length=1)
  'date' => string '2012-04-27 00:00:00' (length=19)
  'source_id' => string '1' (length=1)

array
  'id' => string '3' (length=1)
  'date' => string '2012-04-27 15:51:29' (length=19)
  'source_id' => string '2' (length=1)

array
  'id' => string '4' (length=1)
  'date' => string '2012-05-23 00:00:00' (length=19)
  'source_id' => string '1' (length=1)

array
  'id' => string '5' (length=1)
  'date' => string '0000-00-00 00:00:00' (length=19)
  'source_id' => string '2' (length=1)

array
  'id' => string '6' (length=1)
  'date' => string '2012-04-27 16:06:36' (length=19)
  'source_id' => string '2' (length=1)

array
  'id' => string '7' (length=1)
  'date' => string '2012-04-27 16:16:51' (length=19)
  'source_id' => string '1' (length=1)

array
  'id' => string '14' (length=2)
  'date' => string '2012-04-27 16:45:27' (length=19)
  'source_id' => string '4' (length=1)

array
  'id' => string '16' (length=2)
  'date' => string '2012-04-27 16:58:04' (length=19)
  'source_id' => string '4' (length=1)

End:
boolean false

----------------------
One result
----------------------

array
  'id' => string '1' (length=1)
  'date' => string '2012-04-27 00:00:00' (length=19)
  'source_id' => string '1' (length=1)

End:
boolean false

----------------------
No results
----------------------

End:
boolean false

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.