Page 1 of 1

alphabetical array

Posted: Wed Jul 21, 2010 9:32 am
by aravona
I've got a conditional statement which would draw from a database a single letter ( in this case, g or l )

When I've put this into my if statement, I'm going straight to my else, because my coding has decided my array wants to give 1 and not g as a readout.

I have always sucked at arrays and even with the help of the php manual I'm not able to get this to work o.o

Code: Select all

<?php
	$sql = "SELECT `cloth` FROM `ver_pro` where `pID` ='1' AND `prCode` = '" . $row->prCode . "'";
	$cloth = mysql_query($sql) or die(mysql_error());
	$cloth_data = mysql_fetch_array($cloth);
	if ($cloth_data['cloth'] == 'g'){
	require_once('g.php');
	}
	else {
	require_once('l.php');
	}
?>

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:05 am
by eruna
This should save you some work:

$file=$cloth_data['cloth'].".php";
require_once($file);

E

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:10 am
by aravona
It would, if it actually fixed the problem I'm having in the first place lol... :(

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:14 am
by pickle
Output the query to the screen, then run the query via the command line - to see if the query actually is returning what you expect. If that doesn't show you the problem, call print_r() on $cloth_data to see if it is what you expect.

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:22 am
by aravona
I did 'echo print_r($cloth_data);' as suggested and I got the following: Array ( [0] => g [cloth] => g ) 1

And when I ran the sql through phpmyadmin, it came up with 'g' as well.

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:34 am
by pickle
This is going to seem redundant, but call:

Code: Select all

echo '|'.$cloth_data['cloth'].'|';
To see if $cloth_data['cloth'] only contains a single character, which is "g"

Re: alphabetical array

Posted: Wed Jul 21, 2010 10:39 am
by aravona
nothings redundant if its eliminating the obvious :)

and yeah, I just got |g| which is what I expected >.<

Ahh found the problem ^^ each product has 4+ version >.< one of them was still blank, so the whole thing was getting its knickers in a twist, I got || on that page, put a g in, all working now :)