PDA

View Full Version : LIMIT query using a variable


assassingod
09-06-2003, 06:14 PM
Im writing a hack that depending on the number entered in vBOptions, will limit the ammount of TR/TD tags there are using a query. I've tried this code:


$uploadcode = $DB_site->query("SELECT uploadcrap FROM portfolio LIMIT $numofportfolio");


Then I use $uploadcode[uploadcrap] in the template
But this only shows one row of code when I entered 5 in options.

Anyone shed some light on this

Xenon
09-06-2003, 07:51 PM
you shouldn't get a single row, as your using an DB result and not a normal array.

you have to add a whileloop fetch_array afterwards :)

assassingod
09-06-2003, 08:29 PM
Good idea, I'll try that - thanks

assassingod
09-06-2003, 08:48 PM
Ok, here is the code i'm using now:


$uploadcode = $DB_site->query("SELECT uploadcrap FROM portfolio LIMIT $numofportfolio");
while($uploadcodes = $DB_site->fetch_array($uploadcode)) {
eval(" \$codecrap = \" " .gettemplate("codecrap_ap")."\";");
}


Then in the codecrap_ap template, I have $uploadcodes[uploadcrap] but I get an error:

"Warning: mysql_fetch_array supplied argument is not a valid MySQL result resource in db_mysql.php

Any ideas why?

Xenon
09-06-2003, 08:52 PM
are you sure $numofportfolio is set at least at 1?

also in your eval code you missed a .

assassingod
09-06-2003, 08:54 PM
$numofportfolio currently is set at 5

And thanks, I was copying off another screen:rolleyes:

assassingod
09-11-2003, 06:42 PM
bump