Page 1 of 1
Newbie needs BASIC array help PLEASE
Posted: Sat Mar 11, 2006 1:22 pm
by StrangeRanger
Please bear with me, I'm reading, learning and I have been searching all kinds of forums and the PHP manual, but I'm having a total brain fart. I'm creating a very simply array and trying to pull that info into a web page, that all works, but for the life of me I can not understand why the word Array has to appear on my web page or more importantly how do I get rid of the word Array on my web page. Please, excuse my noobness and help me get rid of the word Array on my web page. Thank you in advance,
j
Posted: Sat Mar 11, 2006 1:25 pm
by feyd
You're echoing an array itself, not the elements in it. Post your code, we'll nudge you in the right direction (hopefully).
Posted: Sat Mar 11, 2006 9:26 pm
by StrangeRanger
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Ok, please keep in mind I'm learning as I go and I know my code is inefficient, that is I know I could probably use a loop to do what I'm doing, but I haven't gotten to that point yet. I'm learning the basics and building as I go. What I'm trying to do here is I have a table, products, and certain products have certain attributes like Skill_Level, Span, Area etc. Depending on the product code assigned to the product being viewed ('crn'), I want to display a table of those attributes. Products that don't fit in the specified product code range don't get the table displayed because they don't have any of those attributes. Here is the code snippet, be nice, I'm learning:
Code: Select all
<? if ($_GET['crn']>=116 && $crn<=129) { ?>
<?=$wingdetails = array($Skill_Level, $Span, $Area, $Weight_NP, $Loading, $Airfoil, $Motor, $Battery, $salsays, $cdsays);?>
<table width="100%">
<tr>
<td width = "12%">
<? if ($wingdetails[0] != '')
{
echo "<b>Skill Level</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[1] != '')
{
echo "<b>Span (in)</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[2] != '')
{
echo "<b>Area (in²)</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[3] != '')
{
echo "<b>Weight (oz)</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[4] != '')
{
echo "<b>Loading (oz/ft²)</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[5] != '')
{
echo "<b>Airfoil</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[6] != '')
{
echo "<b>Motor</b>";
}
?>
</td>
<td width = "12%">
<? if ($wingdetails[7] != '')
{
echo "<b>Battery</b>";
}
?>
</td>
</tr>
<tr>
<td width="12%">
<? if ($wingdetails[0] != '')
{
echo $wingdetails[0];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[1] != '')
{
echo $wingdetails[1];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[2] != '')
{
echo $wingdetails[2];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[3] != '')
{
echo $wingdetails[3];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[4] != '')
{
echo $wingdetails[4];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[5] != '')
{
echo $wingdetails[5];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[6] != '')
{
echo $wingdetails[6];
}
?>
</td>
<td width="12%">
<? if ($wingdetails[7] != '')
{
echo $wingdetails[7];
}
?>
</td>
</tr>
</table>
<p>
<table width="100%">
<tr>
<td width="7%" class="style3">
<? if ($wingdetails[8] != '')
{
echo "Sal says:";
}
?>
</td>
<td width="93%">
<? if ($wingdetails[8] != '')
{
echo $wingdetails[8];
}
?>
</td>
</tr>
<tr>
<td width="7%" class="style3">
<? if ($wingdetails[9] != '')
{
echo "Cooie says:";
}
?>
</td>
<td width="93%">
<? if ($wingdetails[9] != '')
{
echo $wingdetails[9];
}
?>
</td>
</tr>
</table>
<? } ?>
Edited to include the if part for the second part of this "problem" that I'm working on. If any of the attributes that I'm calling for are empty, I don't want that to show up in the table. Ie: if the product does not have a skill level entered in my products table, I don't want the heading Skill Level to even show up. The code is ugly, but seems to be working for that so far. But again, that dang word Array keeps showing up. Please O PHP gurus, give me a hint. Part of my confusion stems from the fact that I"m not even using "echo". Should I be? I couldn't get the table to show up when I used "echo". Thank you!
j
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Sat Mar 11, 2006 10:15 pm
by StrangeRanger
Oh my god, I'm so stoopid... I found my error! Thanks for the tip on what I was doing Feyd. I had an extra set of {? going! Geesh... Off to learn loops I guess.
j