Jump to content

$row doesn't print


Matpatnik

Recommended Posts

Hi guys,Can some one tell me what's wrong with my code please?What I'm trying to do is get a word and identify the first letter (this is fine), then It have to look in the right table and get the right row (no problem here), then look at each column and echo it (It doesn't echo any column).

	$lettre = $_GET['mots']{0};	$sql = "SELECT * 			FROM mots_" . $lettre . " 			WHERE " . $lettre . "_mot = '" . $_GET['mots'] . "'";	$result = mysql_query($sql)		or die(mysql_error());	$i = 1;	while ($row = mysql_fetch_array($result)) {		echo $row["'" . $lettre . "_" . $i . "'"] . ", ";		$i = $i++;	}

Thank you for your help

Link to comment
Share on other sites

I find my problem and changed

	$i = 1;	while ($row = mysql_fetch_array($result)) {		echo $row["'" . $lettre . "_" . $i . "'"] . ", ";		$i = $i++;	}

for this

	$row = mysql_fetch_array($result);	for ($i = 1; $i <= 16; $i++) {		echo $row[$lettre . "_" . $i] . ", ";	}

Now I just have to find a way to escape the ", " when the column is empty

Link to comment
Share on other sites

It was easier than I thought, I added this before the echo

		if (!empty($row[$lettre . "_" . $i])) {			$space = ", ";		} else {			$space = "";		}

I work good expect the comma at the end

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...