Welcome to WebmasterWorld Guest from 54.227.157.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Trying to figure out how to post rows not columns

looked everywhere and cant find it

     
3:28 pm on Sep 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


Hello and thanks in advance for any help. I am stumped on how to attempt to do this. I am trying to make php pull only certain rows of info into my tables. I have all the info in my database. I just need to know the code to pull it out and have it go into this table..but do it roughly 32 times once for each person in my list because I want it all in the same page. Heres my html code for the table. ( I know how to connect to my database and all that..Just need the code to pull individual data from the rows not the columns. I know how to pull from columns (which is what they pass yds, rush tds, etc, etc are) So i dont think i would need all that code for the table..i dunno you guys are the experts (this is what i want it to look like <snip> but instead of 2 listings there will be 32))


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="13%"><div align="left"><img src="images/team logos/servo.jpg" width="90" height="100" /></div></td>
<td width="87%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="left"><span class="style7">Servo (Servo222)</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Eustis Assassins</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Division</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Experiece: 1st Season</span></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><br />
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td bgcolor="6B2705"><div align="center"><span class="style7">Year</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Record</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">At Home</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Away</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Div Record</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Pass Yds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Pass Tds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Rush Yds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Rush Tds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Off PPG</a></span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Def PAPG</a></span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">INTs</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Def Tds</span></div></td>
</tr>
<tr>
<td><div align="center"><span class="style7">2008</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
<td><div align="center"><span class="style7">0</span></div></td>
</tr>
</table></td></tr>
</table>

[edited by: Servo at 3:39 pm (utc) on Sep. 4, 2008]

[edited by: eelixduppy at 4:48 pm (utc) on Sep. 4, 2008]
[edit reason] removed URL [/edit]

7:40 pm on Sept 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


I am wondering if you are looking for this kind of code.


$output = '';
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$output .= '
<tr bgcolor="FFCCFF">
<td align="center"><span class="style7">' . $row[year1] . '</span></td>
<td align="center"><span class="style7">' . $row[record] . '</span></td>
<td align="center"><span class="style7">' . $row[at_home] . '</span></td>
<td align="center"><span class="style7">' . $row[away] . '</span></td>
<td align="center"><span class="style7">' . $row[div_record] . '</span></td>
<td align="center"><span class="style7">' . $row[pass_yds] . '</span></td>
<td align="center"><span class="style7">' . $row[pass_tds] . '</span></td>
<td align="center"><span class="style7">' . $row[rush_yds] . '</span></td>
<td align="center"><span class="style7">' . $row[rush_tds] . '</span></td>
<td align="center"><span class="style7">' . $row[off_ppg] . '</span></td>
<td align="center"><span class="style7">' . $row[def_papg] . '</span></td>
<td align="center"><span class="style7">' . $row[ints] . '</span></td>
<td align="center"><span class="style7">' . $row[def_tds] . '</span></td>
</tr>';}
echo $output;

Is this what you are looking for? It would build all of the rows/columns and then output them when complete.

[edited by: shdwmage at 7:50 pm (utc) on Sep. 4, 2008]

7:42 pm on Sept 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


the value in the bracket in this case would be the title of the column in the table. I just put names i thought would be accurate in there.

I would also remove the space from your path, just to reduce potential problems, replace it with an underscore, or just remove it all together.

7:56 pm on Sept 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


After re-reading your post, you were asking how to pick just certain rows?

I would add an additional field on your table to flag which ones you are looking to print otherwise, I would just do a where value = "result" or value2 = "result2"

or where new_field = 'yes'

I guess it helps to re-read a bit more before responding!

10:15 pm on Sept 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


Well first off yes i have all my fields with an underscore i just forgot to put it in that way...second thank you very much for responding and your help...i am still new to the whole php thing and am slowly getting it...but i am not real sure how to explain what i want...I am trying to get my database to pull all the info i have on user 1 into that table format.....and then on my next table under that one pull all the info from user 2 and stick it in that same table format......

if you are suggesting that i add a ID field to tag it that fine..but then how do i get it so i only pull certain fields from that row in the table...sorry if this is confusing (i think i am confusing myself..lol)

edit: the whole point of this is i am making a statistics website with a bunch of users (up to 32) and on the user page i want to list all the users with all there stats in that table format for each user. (if that makes it anymore clearer)

[edited by: Servo at 10:24 pm (utc) on Sep. 4, 2008]

11:23 pm on Sept 4, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


Also I am not sure what you mean by doing a where value = "result" ....i dont know how i would apply that..if you could show me the way. so to speak.. it would be much appreciated
1:02 am on Sept 5, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:June 6, 2005
posts:109
votes: 0


shdwmage gave you the all the code you need except for the first couple of lines:

$query = "SELECT * FROM table WHERE..." // You need to complete this
$result = mysql_query($query);

Have a look at SELECT & WHERE at [w3schools.com...] to get you going.

3:20 pm on Sept 5, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


What i was speaking about was building the search.

Below are a couple examples

This example will select every thing that is in table_a where the uid (the user id of the person thats logged in) is equal to 1


SELECT * FROM table_a WHERE uid = 1

The following example is probably a poor coding practice, but you can have a field in your table that corraletes to the user ids that are capable of viewing the file.


SELECT * FROM table_b WHERE access_ids like '%,$uid,%'

In this example the $uid is equal to the user id of the current logged in user. Using the like as well as the % signs will allow you to search just a part of the value thats stored in the database.

So depending on how you want to structure your id field, there are a couple of examples of how you can access the data.

If you would like some more clarification, I will try.

3:22 pm on Sept 5, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts: 24
votes: 0


The way the code I gave you above is written, it will take just those fields out of everything, but you could also do a:

Select year1,record,at_home,away,div_record,... FROM table_a

To just pull the data out of those fields into the array.

Please note the ... is just a continuation of all the fields you want to pull seperated by a comma.

3:27 pm on Sept 5, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


alright cool ill try it out thanks.. I am at work right now..if i have any more questions ill let you know......
1:46 pm on Sept 6, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


Ok I am back and have tried what you have said..and well I am not sure whats wrong...because it accepts the code with no errors but it pulls nothing from my database and i do have info in it.. heres the code:


<?php
$hostname_LL = "localhost";
$database_LL = "database";
$username_LL = "user";
$password_LL = "pass";
$LL = mysql_pconnect($hostname_LL, $username_LL, $password_LL) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_LL, $LL);
$query = ("SELECT 'Record', 'At_Home', 'Away', 'Division_Record', 'Pass_Yds', 'Pass_TDs', 'Rush_Yds', 'Rush_TDs', 'Off_PPG', 'Def_PAPG', 'INT', 'Def_TDs' FROM statistics WHERE ID='19'");
$result = mysql_query($query);
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="13%"><div align="left"><img src="images/team logos/servo.jpg" width="90" height="100" /></div></td>
<td width="87%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="left"><span class="style7">Servo (Servo222)</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Eustis Assassins</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Division</span></div></td>
</tr>
<tr>
<td><div align="left"><span class="style7">Experiece: 1st Season</span></div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><br />
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td bgcolor="6B2705"><div align="center"><span class="style7">Year</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Record</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">At Home</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Away</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Div Record</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Pass Yds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Pass Tds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Rush Yds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Rush Tds</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Off PPG</a></span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Def PAPG</a></span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">INTs</span></div></td>
<td bgcolor="6B2705"><div align="center"><span class="style7">Def Tds</span></div></td>
</tr>
<tr>
<td><div align="center"><span class="style7">2008</span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Record']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['At_Home']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Away']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Division_Record']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Pass_Yds']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Pass_Tds']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Rush_Yds']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Rush_TDs']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Off_PPG']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Def_PAPG']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['INT']; ?></span></div></td>
<td><div align="center"><span class="style7"><?php echo $result['Def_TDs']; ?></span></div></td>
</tr>
</table></td></tr>
</table>

[edited by: Servo at 1:47 pm (utc) on Sep. 6, 2008]

3:57 pm on Sept 6, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


"SELECT 'Record', 'At_Home', 'Away', 'Division_Record', 'Pass_Yds', 'Pass_TDs', 'Rush_Yds', 'Rush_TDs', 'Off_PPG', 'Def_PAPG', 'INT', 'Def_TDs' FROM statistics WHERE ID='19'"

Try:
SELECT Record , At_Home , Away , Division_Record , Pass_Yds , Pass_TDs , Rush_Yds , Rush_TDs , Off_PPG , Def_PAPG , INT , Def_TDs FROM statistics WHERE ID='19'

list each field without the '' and see if it works.

4:01 pm on Sept 6, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 29, 2008
posts:24
votes: 0


Also change the mysql_query($query) to
mysql_query($query) or die(mysql_error())

Your code will also only print one line.


<?php
$output = '';
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$output .= '
<tr bgcolor="FFCCFF">
<td align="center"><span class="style7">' . $row[year1] . '</span></td>
<td align="center"><span class="style7">' . $row[record] . '</span></td>
<td align="center"><span class="style7">' . $row[at_home] . '</span></td>
<td align="center"><span class="style7">' . $row[away] . '</span></td>
<td align="center"><span class="style7">' . $row[div_record] . '</span></td>
<td align="center"><span class="style7">' . $row[pass_yds] . '</span></td>
<td align="center"><span class="style7">' . $row[pass_tds] . '</span></td>
<td align="center"><span class="style7">' . $row[rush_yds] . '</span></td>
<td align="center"><span class="style7">' . $row[rush_tds] . '</span></td>
<td align="center"><span class="style7">' . $row[off_ppg] . '</span></td>
<td align="center"><span class="style7">' . $row[def_papg] . '</span></td>
<td align="center"><span class="style7">' . $row[ints] . '</span></td>
<td align="center"><span class="style7">' . $row[def_tds] . '</span></td>
</tr>';}
echo $output;
?>

This will make it show multiple rows. Plus make it a bit easier on the server as far as resources because it will make the whole table with php, and then print it.

4:26 pm on Sept 6, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


well i made you changes but it still shows nothing... and when i took out the '' for the fields it give me this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT , Def_TDs FROM statistics WHERE ID='19'' at line 1

8:29 pm on Sept 6, 2008 (gmt 0)

New User

10+ Year Member

joined:Aug 31, 2008
posts:9
votes: 0


Dont worry about it anymore I got it figured out...i found an old code and replace some parts with it and it works...dunno why but i am not complaining...thanks for all your help and code