Page 1 of 1

Array / mysql problem [solved]

Posted: Wed May 25, 2005 2:45 pm
by siefkencp
Can any one take a look at this and see what I may be missing?

The problem is with the variable $planned_date I may have my syntax confused. Im not sure. I did try to have it comming out of the array like this $array['$field_name'] but that didn't work for me either. All code is below...

Thanks for any and all help.

Chris

Code: Select all

<?
$mailings = mysql_list_fields("sapcdb", "mail_schedule", $link) or die(mysql_error());
$totalcount = mysql_num_fields($mailings);

$group_query = mysql_query("SELECT * FROM `mail_schedule` WHERE `group_id` = '$g'");
$group_array = mysql_fetch_array($group_query, MYSQL_ASSOC);
?>

<br> 
Viewing Group: <? echo $g; ?><br>
Total Mailings In Cycle: <? print $totalcount; ?><br><br>
To initialize this group's mailing cycle, 
<a href="/admin/admissions/main/mailing/initializegroup.php?g=<? echo $g; ?>">
click here</a>.<br>
<br>
<form name="form1" method="post" action="">
<table>

<? 

for ($i = 1; $i < $totalcount; $i++) {
$fieldname = mysql_field_name($mailings, $i);
$planned_date = $group_array[$field_name];
print $planned_date;

print "<tr>\n
<td>$fieldname</td>\n
<td><input name=\"$fieldname\" type=\"text\" value=\"$planned_date\"></input><br></td> \n
</tr>\n";

}
?>

<br>
<br>
</table>
<input type="submit" name="Submit" value="Submit">
</form>

Posted: Wed May 25, 2005 3:12 pm
by siefkencp
I figured it out. I simply used mysql_fetch_row(); and changed the array to look for $array[$i] ..

Just in case any one else wants to accomplish something similar.

Chris

Posted: Wed May 25, 2005 3:17 pm
by thomas777neo
Does your query

Code: Select all

SELECT * FROM `mail_schedule` WHERE `group_id` = '$g'
return more than one value?

You can also try this:

Code: Select all

$connect = mysql_connect(&quote;z&quote;,&quote;x&quote;,&quote;y&quote;);
mysql_select_db(&quote;a&quote;);

$sql = &quote;select * from xyx&quote;;
$exec = mysql_query($sql);

$arrayResult = array();
$arrayResult&#1111;0]&#1111;&quote;id&quote;]=mysql_result($exec,0,&quote;id&quote;);

echo $arrayResult&#1111;0]&#1111;&quote;id&quote;].&quote;<br>&quote;;
Why do you use

Code: Select all

$fieldname = mysql_field_name($mailings, $i);
Why not put the field name in by hand?
What is the structure of your table?

Posted: Wed May 25, 2005 3:19 pm
by thomas777neo
Sorry, I was busy while you updated your question