Form/Array Help? :(

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

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Form/Array Help? :(

Post by JPlush76 »

I'm getting into arrays today and basically I'm having a brain fart on this one...

what I want to do is take a field from my database which was imploded as an array of peoples favorite bands with a pipe seperator:
IE: nirvana|tool|led zepplin

I want to give them 6 input boxes to add in their bands, but they don't have to do all six and the first time the user goes here, their field is empty because they sign up then add the bands, I keep getting the error:

<br><b>Warning</b>: Uninitialized string offset: 4 in <b>c:\inetpub\wwwroot\dd\st_lists.php</b> on line <b>81</b><br>

Code: Select all

$result = query_db("select * from st_bands where username = '$valid_user'");

$num_rows = mysql_num_rows($result);

$row = mysql_fetch_array($result);

$bands = explode('|', ($row&#1111;"bandlove"]));

$num = 0;
$ct = 1;

for($i=0; $i < 6; $i++)&#123;
echo $ct.". ";
?>
<input type="text" name="favband&#1111;]" size="30" value="<? echo $bands&#1111;$num]; ?>"><BR>
<?
$num++;
$ct++;
&#125;
?>
<BR><BR>
     <input type="submit" value="Update »" name="submit">
	 </form>
thats what I've been working with so far. any thoughts on how to do it right? :(

I know the error comes from not having a value there but I'm not sure on how do do value checks for the array
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Code: Select all

$ct = 1; 
foreach ($bands as $band_name) &#123; 
   echo $ct.". "; 
?> 
<input type="text" name="favband&#1111;]" size="30" value="<? echo $band_name ?>"><br> 
<?php 
   $ct++; 
&#125;

if ($ct <= 6) &#123;
   for ($i=$ct; $i < 6; $i++) &#123;
      echo $i.". ";
?>
<input type="text" name="favband&#1111;]" size="30" value=""><br>
<?php
   &#125;
&#125;
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

that did the trick, thank you ever so much!
Post Reply