Array / mysql 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

Post Reply
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Array / mysql problem [solved]

Post 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>
siefkencp
Forum Commoner
Posts: 69
Joined: Thu Dec 16, 2004 8:50 am

Post 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
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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?
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Sorry, I was busy while you updated your question
Post Reply