|
||||
| Register--Login--Top 20 Posters--Search Topics |
Forum Main>>Tutorials>>Specifying how many columns per row when extractng from mysq | ||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 PM [Chipmunk] View Member Photo | Last replied to on Sun Nov 25, 2007 14:18:24 Edit Post|Quote This is a simple tutorial that shows you how to make information or images(in this case buttons) display in a specific number columns per row using a specific algorithem and loop. First for this example, create a table in mysql called affiliates with the follwing fields: affiliateID -primary, auto-increment, bigint URL - varchar, length 255 button - varchar length 255 URL will store the URL of the site you want to link to, and button will how the URL of the button of that site. Now you need a simple connector file like the following connect.php to connect to the database.
Replace username, password, and database_name with your mySQL username,password, and database name. Now populate the table with some data. Then the actualy file to extract and put the data into a table is as follows:
Entries per line is how many columns per row(in the case, how many buttons to display) per row to display in the table. Right now it is set to five, changing it to different number will cause the table to have different # of columns per row. basically the way it is done is that the $counter variable tracks how many buttons it has displayed so far. Since $entriesperline is how many to display per row, when $counter is a multiple of $entriesperline plus 1, it should start a new row. This is exhibited by the
line. The condition says if this condition happens then print <tr> which is the code for starting a new table. Likewise if $counter is a multiple of $entriesperline, you have to end a row, so the next if statement:
The condition tells it to print a </tr>, which ends a table. However, if there isn't a multiple of $entriesperline for total number of entries in a table, the row won't close. Thats what
is for. If the counter doesn't end on a table end, that line will end the table so as to finish what the loop left out. ----------------------------- Chipmunk, Supreme Administrator | |||||
| itsjustdell Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 12202 [PM itsjustdell] RPS score: 0 RPS challenge | Posted at Thu Apr 05, 2007 19:45:00 Edit post|Quote am tryin to make this display 3 column per row, what am i missing or what am i doing wrong?
<? $en['lp_ind'] = 0; ?><!--[Loop Start QUERY:SELECT *,q_name_<%lang%> AS q_name FROM $questtable WHERE q_type=4 ORDER BY q_order ASC]--><? if ($en['lp_ind'] == 0) $en['lp_ind'] = $en['loops_left']+1; $en['lp_ind']--;?><!--[Loop Start QUERY:SELECT * FROM $membtable LEFT JOIN $picstable ON i_user=m_id LEFT JOIN $onlinetable ON o_id=m_id WHERE i_status=2 AND m_confirmed>0 ORDER BY `m_date` DESC LIMIT 100]--><? $en['ftr']++; ?><!--[If Start $en['ftr'] == 1]--><!--[If End]--><!--[If Start $en['loops_index'] == 1]--><!--[If End]--><table border="0" cellpadding="0" cellspacing="4" bgcolor="#FFFFFF" style="margin:3; border:1px dotted #C0C0C0; " width="205"><tr><td rowspan="3" width="65"><a href='<%dir%>view/<%m_user%>.html'><img src='<%dir%>images/pictures/<%m_id%>-<%i_id%>.jpg' width="55" height="55" style="border: 5px solid #c0c8d3;"></a></td><td align="right" width="45" valign="bottom"><font color="000080">name :</font></td><td valign="bottom" align="left" width="128"><a href='<%dir%>view/<%m_user%>.html'><%m_user%></a></td></tr><tr><td align="right" width="45"><font color="000080">age :</font></td><td align="left" width="128"><? $en['mm_year'] = $en['m_year']; $en['mm_month'] = $en['m_month']; $en['mm_day'] = $en['m_day']; echo age(); ?></td></tr><tr><td colspan="2" valign="middle" style="border-top: 1px dotted #C0C0C0"><p align="center"><a href="<%dir%>index.php?req=compose&to=<%m_user%>">send message</a></td></tr></table><!--[If Start $en['loops_left'] == 0]--><!--[If End]--><!--[Loop End]--><!--[Loop End]--><!--[If Start $en['ftr'] > 0]--><!--[If End]--> | |||||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 [PM Chipmunk] View Member Photo | Posted at Thu Apr 05, 2007 20:06:37 Edit post|Quote Please use the [.code] and [./code] tags without the . when posting code, I can't read what you just wrote. ----------------------------- Chipmunk, Supreme Administrator | |||||
| 2Gun Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 14260 [PM 2Gun] RPS score: 0 RPS challenge | Posted at Sat Nov 24, 2007 19:14:32 Edit post|Quote Chipmunk ...Ive been reviewing your code for displaying images and limiting the number of images per row but havent had any luck getting this to work. If you wouldnt mind ill paste my base source snippet for a image gallery/product list to show you the core for it.
| |||||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 [PM Chipmunk] View Member Photo | Posted at Sun Nov 25, 2007 14:18:24 Edit post|Quote Where's your counter for how many columns per row it currently has? ----------------------------- Chipmunk, Supreme Administrator | |||||
Page: 1 |