xyn Posted October 7, 2006 Share Posted October 7, 2006 HeyIs there a way of fetching an array from MYSQL to get somethinglike; $row[field_name][1]where as:[field_name] being the field name[1] being table row 1.Basically I am having problems arranging my table, it's hard to explainbecause i don't want to list the informatino in rows, I want to list it4 rows across and 2 rows down :/ Check my website for what i mean... [url=http://www.eumod.co.uk/en/index.php?x=bio]http://www.eumod.co.uk/en/index.php?x=bio[/url] Link to comment https://forums.phpfreaks.com/topic/23260-mysql-arrays/ Share on other sites More sharing options...
Barand Posted October 7, 2006 Share Posted October 7, 2006 See http://www.php.net/mysql_resulteg[code]$val = mysql_result($result, $row, 'field');[/code]Although there are other ways of doing it, such as CSS or tables (see FAQ) Link to comment https://forums.phpfreaks.com/topic/23260-mysql-arrays/#findComment-105457 Share on other sites More sharing options...
xyn Posted October 7, 2006 Author Share Posted October 7, 2006 Well i had a look and it's all confusing to me :SThe part i'm unsure about is how it will workin my pageination script...PAGE SCRIPT:[code]<p><span class="heading">Eumod UK Biographies</span><br><span class="text">Welcome to the Eumod UK Biographies, these bios' where created by the vehicle original owners, Click the thumbnail for the main biography view, Members may leave reviews, rate the biography, and send the biography to their friends. Unregistered members must register for these special privileges, it's 100% free and will not take any longer than 2 minutes.</span></p><?PHP////Set Limit//$limit = "8";////Count & Collect//$SQL = mysql_query("SELECT count(*) FROM bio WHERE bio_auth='y' AND bio_done='y'");$NUM = mysql_num_rows($SQL);////Check Page//if(empty($page)){ $page="1";}////Page Values//$pgval = $page * $limit - ($limit);////Limit SQL//$SQL2 = mysql_query("SELECT * FROM bio WHERE bio_auth='y' AND bio_done='y' LIMIT $pgval, $limit");if(mysql_num_rows($SQL2) >0){ //Table Start echo 'table'; //Row: 1 while( $data = mysql_fetch_rows($SQL2)){ echo 'rows';} //End Table echo 'tableend';}else{ echo 'null';}////Set PREVIOUS//if($page != "1"){ $prev = $page--; echo "[ <a href=\"".$_SERVER['PHP_SELF']."&page=$prev\">Prev</a> | ";}else{ echo "Prev | ";}////Collect Pages//$pgnum = $SQL2 / $limit;for($i=1;$i <= $pgnum; $i++){ if( $i == "$page"){ echo $i. " : ";}else{ echo "<a href=\"".$_SERVER['PHP_SELF']."&page=$i\">$i</a> | ";}if(($SQL2 % $limit) != 0){ if($i == "$page"){ echo $i." | ";}else{ echo "<a href=\"".$_SERVER['PHP_SELF']."&page=$i\">$i</a> | ";}////Next Page//if(($SQL2 - ($limit * $page) >0 ){ $nextpg = $page++; echo "<a href=\"".$_SERVER['PHP_SELF']."&page=$nextpage\">Next</a> ]";}else{ echo $i."Next ]";}?>[/code]TABLES:[code][code=php:0]<div align="center"> <center> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="470"> <tr> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> </tr> <tr> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> </tr> <tr> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> </tr> <tr> <td width="470" colspan="7" height="10"></td> </tr> <tr> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> <td width="10"> </td> <td width="110"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="104"> <tr> <td width="100%"> <p align="center">nnnn</p> </td> </tr> </table> </td> </tr> <tr> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> <td width="10" height="10"></td> <td width="110" height="10"></td> </tr> <tr> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> <td width="10" height="24"> </td> <td width="110" height="24"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="110" height="24"> <tr> <td width="100%"> <p align="center">Heading</p> </td> </tr> </table> </td> </tr> </table> </center></div>[/code] Link to comment https://forums.phpfreaks.com/topic/23260-mysql-arrays/#findComment-105460 Share on other sites More sharing options...
printf Posted October 7, 2006 Share Posted October 7, 2006 Normally you create helper functions, when dynamic content logic is needed, the helper functions create the arrays of rows and columns formatted to fit your display, so if you don't have enough data the helper functions can stop another row from being displayed or fill empty elements when there is room for another row, but not enough elements to fill the entire row.You could do this in your db result loop, but it gets messy and will always have to be changed is your row or column logic changes, so creating helper functions that can handle any amount or different types of (row and column) displays will be better, plus you will have reusable code that you can use anytime you need this kind of logic in your other applications!Also this...[code]$SQL = mysql_query("SELECT count(*) FROM bio WHERE bio_auth='y' AND bio_done='y'");$NUM = mysql_num_rows($SQL);[/code]Will always return (1) row for $NUM, because mysql_num_rows returns how many rows were returned, which will always be (1) when using COUNT()! Use mysql_result or mysql_fetch_..., to get the value for COUNT()!me! Link to comment https://forums.phpfreaks.com/topic/23260-mysql-arrays/#findComment-105473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.