Functions, Fors, While, Foreach, Arrays: Problem [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

danf_1979
Forum Commoner
Posts: 72
Joined: Sun Feb 20, 2005 9:46 pm

Post by danf_1979 »

I get no output with that... inside the function or outside...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

then you're doing something wrong..
danf_1979
Forum Commoner
Posts: 72
Joined: Sun Feb 20, 2005 9:46 pm

Post by danf_1979 »

Ok, I got something new going on, I think I'm in the right direction

Code: Select all

function prueba ($edit) {
if ($edit !== 0){
	for ($x = 1; $x <= 8; $x++) &#123;
	$query_edit_pregunta = "SELECT pregunta FROM enc_preguntas WHERE idvotacion='$edit' AND idpregunta='$x'";
	$result_edit_pregunta = mysql_query($query_edit_pregunta) or die ("Error in query: $query_edit_pregunta. ".mysql_error());
		while ($registro_edit_pregunta = mysql_fetch_row($result_edit_pregunta))
			&#123;
				 $get_edit_pregunta&#1111;] = $registro_edit_pregunta;
					&#125;
				&#125;
			return $get_edit_pregunta;
			
				&#125;
			&#125;
			
			

$var = prueba ($edit);
for ($x = 0; $x <= 8; $x++) &#123;
echo "&#123;$var&#1111;$x]&#125;<br>";
&#125;
What you told me about the foreach I think is OK, now I got the 3!!! answers, but as "Array". Before, I got only 2 because the for loop wha beginning from $x=1 and somehow the while loop begins from 0, or I think at least...
Now, how can I get to the Array stuff? How can I read the content?
Thanks very much!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

print_r($var).. it's all in arrays..
danf_1979
Forum Commoner
Posts: 72
Joined: Sun Feb 20, 2005 9:46 pm

Post by danf_1979 »

Ok, you were right, but I got this little problem with the output.

Code: Select all

$var = prueba ($edit);
for ($x = 0; $x < count($var); $x++) &#123;
print_r($var&#1111;$x])."<br>";
&#125;
returns:
Array ( [0] => ¿Qué busca en nuestro sitio web? ) Array ( [0] => ¿Cómo conoció nuestra empresa? ) Array ( [0] => A usted le interesaría… )
And I'm almost there... but I'm not :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo $var[$x][0];

within the for loop.. time to play a lot with arrays :P
danf_1979
Forum Commoner
Posts: 72
Joined: Sun Feb 20, 2005 9:46 pm

Post by danf_1979 »

Thank U!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I love this forum!!! I'm never leaving!!
Post Reply