Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Table screwing up PHP
  
User name:
Password:
Reply:
 

UserPost
Weasel
Posts: 424/454
On the topic of fetching, Coby's way is nicer in the fact that it's bloody easier to read. Split it up into multiple lines. Imagine if someone else were to read your source code. They'd go mad.

For example, read out loud
$inf=mysql_fetch_array(etc....)

compared to
$inf = mysql_fetch_array( etc... )

Even something like using spaces between things helps a great deal with readability.
Putting a fetch array and a query on separate lines helps a bit too. If you had an error and it said line 3, and all that crap was on line 3, you might have trouble figuring out where to put the fix. Debugging is easier when it's on a separate line.
Darth Coby
Posts: 722/1371
Originally posted by Mercury
There is nothing wrong with the fetching .
I always do it like that, never have any problems.

And it's the table indeed, because when I leave out the table, it works fine.
I'll try and add the /'s .


\s :p
And the fetching seems awfully wrong to me. :O But njeh, if it works then uhm.. Ok I guess.
Mercury
Posts: 12/88
There is nothing wrong with the fetching .
I always do it like that, never have any problems.

And it's the table indeed, because when I leave out the table, it works fine.
I'll try and add the /'s .
Darth Coby
Posts: 719/1371
Woah, that's uhm. Not a way to do it. O_o

You can't fetch an array like that, well not that I know of. Try this code, this one should work.

$sql = mysql_query("SELECT credits, lvl, exp, expnext FROM users WHERE id = '$loguserid' LIMIT 1");
$inf = mysql_fetch_array($sql, MYSQL_ASSOC);
print "<table border=0 cellpadding=0 cellspacing=0 width=100% height=15>
<tr>
<td valign=bottom width=20%><b>Level:</b> $inf[lvl]</td>
<td valign=bottom width=50% align=center><b>Experience:</b> $inf[exp]/$inf[expnext]</td>
<td valign=bottom width=30% align=right><b>Credits:</b> $inf[credits]</td>
</tr>
</table>";

You FIRST store the MySQL query into the variable $sql and then you use MySQL fetch array on the variable $sql wich now contains the data that was grabbed from the DB. Then you select how to give out the information. That last past wasn't explained correctly, it just means the different ways of uhm.. Printing them, if you would take MYSQL_NUM then you'd have the use the column numbers, ASSOC means name and number and the other one I forgot. (Correct me if I'm wrong)


EDIT: Err, you said it was the fault of the table? Try putting \s infront of the % signs and such and make sure that you also have \s before any quotation marks.
Mercury
Posts: 1/88
I have this script where you can click following button:

<INPUT TYPE=SUBMIT CLASS=SUBMIT NAME=submit3 VALUE=\"Run Away\">

When you click that, this happens:

if($submit3){
mysql_query("UPDATE users SET btemp = 0,btemp2 = 0, btemp3 = 0 WHERE id = '$loguserid' " ) or exit("Error 'flee @ btemp'" );
header("location: explore.php" );

This was working fine, you went to explore.php and could see the content.
But than I added this in the PHP page:

$inf=mysql_fetch_array(mysql_query("SELECT credits,lvl, exp, expnext FROM users WHERE id='$loguserid' LIMIT 1" ));
print "<table border=0 cellpadding=0 cellspacing=0 width=100% height=15><tr><td valign=bottom width=20%><b>Level:</b> $inf[lvl]</td><td valign=bottom width=50% align=center><b>Experience:</b> $inf[exp]/$inf[expnext]</td><td valign=bottom width=30% align=right><b>Credits:</b> $inf[credits]</td></tr></table>";

And it stopped working, it just showed a blank page.
I found out the problem is because of the table, because if I leave out the table and just print the level, exp etc. it works .

What's wrong?
Acmlm's Board - I2 Archive - Programming - Table screwing up PHP


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.011 seconds.