SunQuest
 
      SQL Basics
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 11th, 2005, 01:47 PM
LLX LLX is offline
Senior Member
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Glendale, CA
Posts: 285 LLX New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to LLX Send a message via MSN to LLX
Reguarding SQL

say im using the select * to grab al fiends in a table is there a way short of hand naming ieach field that PHP can grab the field ID in the SQL file?
__________________
24y-CW, 8y-HTML, 5y-PS, 8m-PHP
And I never knew Photoshop could do HTML!
You learn something every day.

http://lexxboard.lurkerlordx.com/listcatagories.php

Reply With Quote
  #2  
Old January 11th, 2005, 02:49 PM
kurt kurt is offline
Administrator
Tutorialized Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 514 kurt New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 m 48 sec
Reputation Power: 0
Sure, you'll use the mysql_fetch_assoc function.

Code:
$query = "select * from users";
$result = mysql_query($query);

$first_row = mysql_fetch_assoc($result);

$user_id = $first_row['user_id'];
$password = $first_row['password'];


or, to loop through it:

Code:
$query = "select * from users";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {

  $user_id = $row['user_id'];
  $password = $row['password'];

  print "user: $user_id, password: $password
";
}

Reply With Quote
  #3  
Old January 11th, 2005, 03:56 PM
LLX LLX is offline
Senior Member
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Glendale, CA
Posts: 285 LLX New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to LLX Send a message via MSN to LLX
i know about that what i trying to do is automate the

$first_row['user_id'];
$first_row['password'];

see what i basicly want to do is dynamicly genererate a header row in a table, as it stands now i have to tell type out 37 lines of code for 37 fields i want to stop doing

<td>field title 1</td>
<td>field title 2</td>
<td>field title 3</td>
<td>field title 4</td>
...
<td>field title 37</td>

and find a way to automate and print that
"$first_row[something];"
field

the value in row one of Field A but the actual name of field A, grabed dynamicly

Reply With Quote
  #4  
Old January 11th, 2005, 05:05 PM
kurt kurt is offline
Administrator
Tutorialized Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 514 kurt New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 m 48 sec
Reputation Power: 0
oh I gotcha, you want to print out the name of the field, not the contents of it.

well when you do the mysql_fetch_assoc, it creates an array with an array element for each field, and that array element has the field name.

so:

Code:
$array_size = count($array);
$count = 1;

print "<table><tr>";
while ($count <= $array_size) {
    print "<td>".$array[$count-1]."</td>";
    $count++;
}
print "</tr></table>";

Reply With Quote
  #5  
Old January 11th, 2005, 05:43 PM
LLX LLX is offline
Senior Member
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Glendale, CA
Posts: 285 LLX New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to LLX Send a message via MSN to LLX
thanks as it stands now i use 37 function calls one for each TD....

would this also worl for making a blank row (as a spacer)

Code:
echo '<TR><TD colspan='.$array_size.'></<TD></<TR>';

Reply With Quote
  #6  
Old January 11th, 2005, 05:47 PM
kurt kurt is offline
Administrator
Tutorialized Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 514 kurt New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 5 m 48 sec
Reputation Power: 0
It should, give it a shot.

Reply With Quote
  #7  
Old January 11th, 2005, 05:54 PM
LLX LLX is offline
Senior Member
Tutorialized Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Glendale, CA
Posts: 285 LLX New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to LLX Send a message via MSN to LLX
oddy it only partiall workms maybe im doing it wrong but heres the relevent code, note i kept my function calls as a compair against at the moment

Code:
echo '<Table border=1><TR>';


$query = "SELECT * FROM nannies Order by Applicant_ID_Number";
$result = mysql_query($query, $db) or die(mysql_error());

$row = mysql_fetch_assoc($result);

$array_size = count($row);
$count = 1;

while ($count <= $array_size) {
    echo "<td>".$row[$count-1]."</td>";
    $count++;
}
print "</TR><TR>";

HeadRepeater("ID Number");
...A heck of a lot more...
HeadRepeater("Agency List");

echo '</TR><TR><TD colspan='.$array_size.'></TD></TR>';

the blank array_size row works, and the header repeat functions work but not the field name display

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Reguarding SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway