Jump to content

Recommended Posts

Good day,

I'm having trouble putting data from MySQL into my array. Here's what I've got:

 

<?php

require("../api/cal.api");
$connect = db_connect();
mysql_select_db($GLOBALS["db"]);
$query = "SELECT * FROM calendar_messages WHERE msg_id='$id'";

$result = mysql_query($query);
if( !$result ){
  echo mysql_error() . ": " . mysql_errno();
}
$event = mysql_fetch_array($result);

$event["msg_text"] = str_replace("<br> <br>\n" , "\n\n" , $event["msg_text"]);
mysql_close($connect);

$splashtext = "Modify <b>" . $event["msg_title"] . "</b> for " . $event["msg_month"] . "/" . $event["msg_day"] . "/"
              . $event["msg_year"];
if( $event["msg_recurring"] ) $splashtext .= " (and associated recurring events)";

?>

 

My problem is, $event seems to come out as an empty array. Any idea why?

Link to comment
https://forums.phpfreaks.com/topic/137057-solved-php-mysql-question/
Share on other sites

Check that you don't have a problem with array types.  There are two types of array, associative and numeric.  If you have an associative array you have to use field names to display data, if numeric then you have to use field array positions. 

 

http://www.w3schools.com/PHP/func_mysql_fetch_array.asp

 

So check that the type of array you are calling and the technique to display your data (field name or field array positions) match. 

 

Rgds

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.