Page 1 of 1

Putting stuff into multi-arrays

Posted: Mon Oct 17, 2005 5:09 am
by Ralle
hello, here is my script!

Code: Select all

<?
//Variables
require_once('connect.php');
$cat = $_GET[id];
if ($cat == NULL) {$cat = 0;}
$resulta = mysql_query("SELECT * FROM categories WHERE cats_approved=1 AND cats_subcat=$cat");
$resultb = mysql_query("SELECT * FROM links WHERE links_cat=$cat");

//Categories
while ($row = mysql_fetch_array($resulta, MYSQL_BOTH))
	{
	$i++;
	if ($i == 1) {echo 'categories<br><table border="1">';}
	$link = "<a href=" . viewcats . "?id=" . $row['cats_id'] . ">" . $row['cats_name'] . "</a>";
	echo "<tr><td>$link</td></tr>";
	}
if ($i > 0) {echo "</table>";}
//echo "<a href=" . viewcats . "?id=$cat>back</a>";
//Output Links
while ($row = mysql_fetch_array($resultb, MYSQL_BOTH))
	{
	$o++;
	if ($i == 0) {echo 'links<br><table border="1">';}
	$link = "<a href=" . viewlink . "?id=" . $row['links_id'] . ">" . $row['links_name'] . "</a><br>";
	$url = $row['links_url'];
	$description = $row['links_desc'];
	$hits = $row['links_hits'];
	$banner = $row['links_banner'];
	
	echo "<tr><td>$link<br>$description</td></tr>";
	}
if ($o > 0) {echo "</table>";}
?>
I would like to have the variables $row to be a multi variable so if I wrote:

Code: Select all

echo "$row[1]['links_id']";
it would say some number. I want everything it pulls out of the database in this small $row. how is that possible?
NOTE: I played around with it but didnt make it to work, listed above is my backup script.

Posted: Mon Oct 17, 2005 5:16 am
by shiznatix

Code: Select all

<?
while ($row = mysql_fetch_array($resultb, MYSQL_BOTH))
    {
    $o++;
    if ($i == 0) {echo 'links<br><table border="1">';}
    $link = "<a href=" . viewlink . "?id=" . $row['links_id'] . ">" . $row['links_name'] . "</a><br>";
    $url = $row['links_url'];
    $description = $row['links_desc'];
    $hits = $row['links_hits'];
    $banner = $row['links_banner'];
    $new_row[$o]['links_url'] = $row['links_url']; //repeat this with the rest of the $row things
    echo "<tr><td>$link<br>$description</td></tr>";
    }
if ($o > 0) {echo "</table>";}

print_r($new_row);
?>
is that what you mean?

Posted: Mon Oct 17, 2005 5:46 am
by Ralle
Thank you man!
I will add this site to favorites!

Posted: Mon Oct 17, 2005 7:13 am
by shiznatix
Ralle wrote:Thank you man!
I will add this site to favorites!
thats a very good idea.

Posted: Mon Oct 17, 2005 11:12 am
by Jenk

Code: Select all

<?php

$rows = array();

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

  $rows[] = $row;

}
?>