Jump to content

PHP Array Help...


cbastian

Recommended Posts

I'm new to PHP, so forgive me if this is a stupid question.

 

I've got a bit of code :

<?php
require("connect.php");

$sql = "SELECT * FROM table1 WHERE group = 7";
$res = mysqli_query($mysqli, $sql);

if ($res) {
   while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
      $title = $newArray['evnt_title'];
      }
} else { printf("could not retrieve records: %s\n", mysqli_error($mysqli));
}
mysqli_free_result($res);
mysqli_close($mysqli);

?>

 

It works fine on a page I made to create PDF files, from a database.  But when I tried to use it to grab data from a different database, to list events on another page, it keeps returning:

 

"PHP Notice: Undefined variable: title in F:\..... on line 202"

 

This script is in a different file from the page, and the page is requiring it.

 

The page that I'm trying to display it on, is using an array to create different pages.  like this:

 

$tarr = array("Music"=>"?mdc=mus");
............
Private function pageswitch($mod){
   if($mod=="mus"){
      $ts = $this->dualMN(1);

return $ts;
}
.............
private function dualMN($t){
   $ts1 = array(
      1=>array(
          "title"=>"music",
          "cont"=>"<p class=\"arttitle\">Music</p><br/>
                       <ul><li>
                             <div class=\"arttitle\">Scheduled events<br/>
                             <p class=\"artbody\">title=".$title."</p><br/>
                             </div></li>
                       </ul>
                   ")
                   );
}

 

the page displays fine, but when I put this in, instead of showing the data from the database, it just shows "title" and places the above error in the PHPerrors file.

 

I can't figure out why it is not recognizing the variables, and showing their data...

 

Hope this makes sense.  any help anyone can give me, would be greatly appreciated.

 

Thanks,

Charles...

 

Link to comment
Share on other sites

OK, I tried putting this in the main page file :

private $title;

function setTitle ($t) {$this->title = $t;}

 

and then this in the dualMN

Then use $this->title in the dualMN function.

 

like this:

<p class=\"artbody\">title=".$this->title."<br/>........

 

But it shut down the whole page. and gave the error:

"PHP Parse error: Syntax error, unexpected T_PRIVATE in f:\..... on line 11"

 

Am I missing something?  Or am I putting it in there wrong.  Sorry, like I said I'm new to this, kinda got thrown into it...:)

 

thanks for your help.

-Charles...

 

Link to comment
Share on other sites

Post the first 11 lines. A parse error usually denotes a mistake somewhere before the line that it eventually reports.

 

<?php 
require("../html_temp_sets/pageset.php");
require("../html_temp_sets/dataset.php");
require("./events.php");

private $title;

function setTitle ($t){$this->title = $t;}

class FINEART{
public function FAMain(){

 

and the line trying to display it is:

 

".......
<li>
   <div class=\"arttitle\"><strong>Scheduled Events</strong><br/>
      <p class=\"artbody\">title=".$this->title."<br/>
      </p>
   </div>
</li>
........";

 

Not sure what coulde be wrong with it.  If I remove those new lines it works fine (without displaying the database info)...

 

Thanks A lot, for your help...

 

--Charles...

 

Link to comment
Share on other sites

OK, that brought it back up, and eliminated the undefined variable error.  But, it still isn't showing anything.  And it's not giving any errors...  Any ideas why?  Think I should just put the script to grab data from the database in the same class?  Instead of having it in another file and calling it?

 

Thanks for your help...

--charles...

 

Link to comment
Share on other sites

OK, this is probably a stupid question, but how would I do that?

is it just like this:

 

setTitle($title);

inside the class somewhere?  I tried just doing that, and it killed the page again, giving the unexpected T_String error.  Or do I need to create a new function and put it in there?

 

Thanks a lot for your help!

--charles...

 

Link to comment
Share on other sites

OK, I'm feeling pretty stupid right now...  :) 

There is nothing in my files that says $xxxxx = new FINEART;

 

and the only place I can find pageswitch is in this line:

$td .= pageSet::tdSetsimple($this->pageswitch($mod),"valign='top' class='artbody'");

 

and this line (that calls the arrays for what's on each page):

private function pageswitch($mod){

 

?????

I'm working with someone else's code, who had my job before me, and left things about half done... I might just have to stop trying to edit and just rewrite the page from scratch...  ?????

 

Thanks!

-Charles...

 

Link to comment
Share on other sites

this method should work

 

<?php
class FINEART {

private static $title;

public function setTitle($t)
{
	FINEART::$title = $t;
}

function printTitle()
{
	echo FINEART::$title;
}
}

$title = 'abc';                                               // value from database

FINEART::setTitle($title);                             // set value in the class

FINEART::printTitle();                                 // call you function which uses $title
?>

Link to comment
Share on other sites

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.