Jump to content


Photo

[resolved] Stupid code is not working


  • Please log in to reply
3 replies to this topic

#1 spare

spare
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 August 2006 - 10:24 PM

Hello,

Could somebody please help me.  This is just about to drive me crazy.  I have been beating my head for countless hours over the past two days. 

I am trying to add one of those annoying algorythim images to a registration page.  I have a db table with fields named id, code, and codename.

I want a random selection of a 'codename' (also the name of an image in a folder).  The results of the 'codename' will, via a switch, display the matching image. The related 'code' field will be required to match what the visitor has entered in the text field on the registration page or else an error message.

The basic query works on PHPMyAdmin but the results won't echo on the registration page and echo as 'empty' when I run it on another page.

$regcd= "SELECT * FROM ".$glob['dbprefix']."ATC_humanreg WHERE id >0 ORDER BY RAND() LIMIT 1";
 
$results=$db->mySQLsafe($regcd[0]['codename']);

echo '<pre>';
print_r($regcd);
echo '</pre>';
echo '<pre>';
print_r($results);
echo '</pre>';
This is what I get back

SELECT * FROM ATC_humanreg WHERE id >0 ORDER BY RAND() LIMIT 1

''

When I try
$regcd = "SELECT codename FROM ".$glob['dbprefix']."ATC_humanreg WHERE id >0 ORDER BY RAND() LIMIT 1";
 
$results=$db->mySQLsafe($regcd[0]['codename']);

echo '<pre>';
print_r($results);
echo '</pre>';
I get this

''

Why are the query result not appearing?  What am I doing wrong?

I appreciate any help or suggestions.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 22 August 2006 - 10:45 PM

$regcd is a string... you define it yourself. You then try and reference it as some sort of multidimensional array. $regcd[0]['codename'] Whats with that?

#3 spare

spare
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 August 2006 - 01:17 PM

$regcd is a string... you define it yourself. You then try and reference it as some sort of multidimensional array. $regcd[0]['codename'] Whats with that?

The onset of complete burnout. :P 

I'm getting it..... Oookay.  I got it. 

Thanks

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 01:32 PM

I'm getting it..... Oookay.  I got it.


Does that mean the thread is resolved? Ive marked it so... please do so yourself in the future.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users