PDA

View Full Version : Querying and such.


gengar003
06-05-2003, 11:26 PM
I know there's a way to do this, but I'm not sure what....

I want to select information from a table in mySQL, only 2 fields in the table, `name`, and `data`, and I want it to repeat a piece of code until there's none left.... Hard to express my idea...


global $count
(Insert code looping until it's read all of table `query`)
$name = (insert way to call the current row's `name`field)
$dat = insert way to call the current row's `data`field)

echo $name;
echo "=";
echo $dat;
$count ++

(insert end of loop stuff)


A
||
||

That... What should be `insert` 'ed?

Also, how would I query 2 out of 3 fields, or only 1?

Dean C
06-06-2003, 10:13 AM
<?php
<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">
$getstuff = $DB_site->query("SELECT item1,item2 FROM table ORDER BY item1");
while($lala = $DB_site->fetch_array($getbattles))
{
<tr>
<td>$lala[item1]</td>
<td>$lala[item2]</td>
</tr>
}
</table>
?>


That will do it :)

- miSt

gengar003
06-09-2003, 12:02 PM
Just one question.... where on earth did $getbattles come from? .... ? :confused"

Boofo
06-09-2003, 12:10 PM
$getbattles should actually be $getstuff

Chris M
06-09-2003, 12:41 PM
It is probably something he was thinking about at the time;)

And yes - '$getbattles' = '$getstuff'

Satan

gengar003
06-09-2003, 02:37 PM
Okay, using that code, I've modified it to run through a table, called "tacemon" until there's nothing left, and each time, execute a bit of code:


$mypkmndat = "";
$tacemonqing = $DB_site->query("SELECT name,catchname FROM tacemonquery ORDER BY name");
while($loopy = $DB_site->fetch_array($tacemonqing))
{
$th_rite_name = $loopy[name];
$th_rong_name = $loopy[catchname];


if ($bbuserinfo[$catchname]=="1") {

$mypkmndat .= "<img src=\"http://pgsforum.com/vb/images/tac/tac/caught/";
$mypkmndat .= $th_rite_name;
$mypkmndat .= ".gif\">";
} else {
}


}

$bbuserinfo['tacemon'] = $mypkmndat;

$DB_site->query("UPDATE user SET tacemon = '".$bbuserinfo[tacemon]."' WHERE userid='".$bbuserinfo['userid']."' LIMIT 1");



Anyway, When I hard-code the code in the while loop for each entry in the DB table, it works, but not when I use the loop. However, when I place an "echo $loopy[name];" in the loop, but not in the if statement, It prints the names on the page, so I know the loop works.


This probably has to do with global/local variables, but I tired declaring $mypkmndat as global (Which I assume is the problem, since it's the variable that I want to use outside of the loop) but that didn't help.

Anyway, anyone know what I've done wrong?

EDIT: *sigh* after all that typing describing my problem, I found the answer going over my post. $catchname should've been $th_rong_name. I changed it, an' it works.

:o :o :o :o :dead: :mad: :nervous: :cry:

Now the real test will be how it handles me adding a new row...

gengar003
06-09-2003, 03:10 PM
Anyway, another question. I get this error:

Warning: Cannot use a scalar value as an array in /home/pgsforum/public_html/catch.php on line 55

Warning: Cannot use a scalar value as an array in /home/pgsforum/public_html/catch.php on line 56

Warning: Cannot use a scalar value as an array in /home/pgsforum/public_html/catch.php on line 99

Warning: Cannot use a scalar value as an array in /home/pgsforum/public_html/catch.php on line 115

on every vbhome(lite) page.

What would I look for to fix it? Is it something like trying to do

$var ="0";
$arrary[$var] = $arryvar?

(Quoted variable value used as thingy in an array?)

Plz help.

Also, the # of new threads, posts, articles, and messages aren't showing up....

Chris M
06-09-2003, 07:09 PM
It is possible you globalised a variable used by vBhome(lite)...

Satan

gengar003
06-09-2003, 07:53 PM
I didn't add any global thingies, though...

Dean C
06-10-2003, 02:32 PM
gengar - oopsiee at the copy and paste job and edit job from my battle script hehe :)

That's basically the jist of it though :)

- mISt

gengar003
06-11-2003, 02:22 PM
Yesterday at 04:32 PM Mist said this in Post #10 (https://vborg.vbsupport.ru/showthread.php?postid=407063#post407063)
gengar - oopsiee at the copy and paste job and edit job from my battle script hehe :)

That's basically the jist of it though :)

- mISt

I have a few questions about your post:

[list=1]
oopsiee?
at the copy?
from your battle script?
...
[/list=1]

What do you mean?

assassingod
06-11-2003, 02:36 PM
Basically he copied that code he posted from his battle hack. He didnt mean to leave in the getbattles varibles in.

gengar003
06-11-2003, 03:51 PM
Oh. That has no bearing on my current problem, then.

Ohk.

Plz read post #7.

Thank you.