Jump to content

indigo diingo

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

indigo diingo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [/code] $m = mysqli_connect('localhost','root',''); $result = mysqli_query($m,"SELECT p_style FROM mydatabase.mytable"); while($row = mysqli_fetch_assoc($result)) array_push($return,$row); $p_style = $return[0]['p_style']; if($p_style === 1) echo 'yeah, the magical numbers is .... 1'; else if($p_style === 2) echo 'to bad, we've got a just a second'; [/code] If p_style can only be one of TWO numbers you better use 0 and 1 instead of 1 and 2. The mysqli stuff is just typed out of my head so there could be some errors. Check the php manual for more info. Greets
  2. Hello everybody! I am building a little PHP framework to build my application on. I almost have everything working great but i have a problem with the loader class and i feel i am never going to solve it on my own. So i have base.php, my base class which instantiates the Loader class ('load'). So every time i need to load the library i just call $this->load->lib('myobject') from within the base class. Now the problem is that the loader class instantiate the library objects withinn the Loader class. So every time i want to access them through the base class or any childclass of the base, i need to call: $this->load->myobject->dosomething(). Instead of that i wanna be able to just call it like $this->myobject->dosomething(). Why do I want this syntax? Because it's shorter, more clear, and makes more sense (you don't load the object again, it's already loaded). How can i accomplish this? class Loader { public function __construct() {} public function lib($objects) { foreach($objects as $var) { // capitalize the first letter $object = ucfirst($var); // load the class require_once __LIB__PATH . $var . '/' . $var . '.php'; // instantiate the class $this->$var = new $object(); } } } Thanks a lot
  3. Thanks dude, That's some clear info you gave me, i appreciate it. The problem is solved but now i have a very difficult script related to the array with subarray topic. So i would like to make a challenge for simplifying. Not because i am lazy (i have worked 3 days on it) but because i believe some of you guys have far more notion about php then me. This what i wrote a function for: $framework = array( 'title', 'stage'=>array('width'=>'','height'=>'','color'=>''), 'values'=>array(), 'texts'=>array(), 'colors'=>array(), 'direction', 'system', 'margin' ); $fruitstock = array( 'Fruit stock', array(670,360,'FFFFFF'), array(10,7,5,10,3,1,, array('peren','appels','bananen','aardbeien','appelsienen','meloenen','bessen'), array('D88A35','3377DB','DB338F','36D69C','CC3B3B','6C39D1','B1D337'), 'vertical', 'relative', 15 ); So my question is, is there a simple and dynamic function for adding the fruitstock array values to the framework without doing it manually? At the moment I have 170 lines of code just to do this! function procesinputs($framework,$statmap) { $array = $framework; $keys = array_keys($array); $values = array_values($array); $i = 0; $j = 0; while($i<count($array)) { $key = $keys[$i]; $value = $value[$i]; if(is_numeric($key)) { $inputs[$array[$j]] = $statmap[$i]; $j ++; } else { $subarray = $array[$key]; $subkeys = array_keys($subarray); $subvalues = array_values($subarray); $subinputs = array(); $k = 0; $m = 0; while($k<count($subarray)) { $subkey = $subkeys[$k]; $subvalue = $subvalues[$k]; if(is_numeric($subkey)) { $subinputs[$m] = $statmap[$i][$k]; $m ++; } else { $subinputs[$subkey] = $statmap[$i][$k]; } $k ++; } $inputs[$key] = $subinputs; } $i ++; } return $inputs; } procesinputs($framework,$fruitstock); I appreciate all the help!
  4. Hi, I am learning more about arrays and now i have a problem: Why does my output array ($inputs) has a missing key, 'values' and is there and empty key with empty value on the end of the array? Can somebody please help me out because this isn't making any sense to me. $array = array('title','stage'=>array('width','height','color'),'values','text','colors','direction','system','margin'); $keys = array_keys($array); $values = array_values($array); $i = 0; while($i<count($array)) { $key = $keys[$i]; $value = $value[$i]; if(is_numeric($key)) { $inputs[$array[$i]] = $_POST[$array[$i]]; } else { $inputs[$key] = 'lala'; } $i ++; } print_r($inputs); Print_r: Array ( [title] => titel [stage] => lala [text] => [colors] => [direction] => horizontal [system] => absolute [margin] => on [] => ) 1 Thanks, indigo
  5. Hi I know the code is long but you can see the result of the problem at http://www.rhythmbeats.be/band/agenda.php The first problem: If you insert two messages, and then a third, the first one gets deleted. If I delete the \n at the end of this code, it all works fine (and in the regex). $nieuw = "<span id=\"$id\">" . '<p class="naam">' . $naam . '</p><p class="boodschap">' . $boodschap . '</p>' . '<p class="datum">' . $datum . " || <a href=\"agenda.php?actie=verwijderen&id=$id\">verwijderen</a></p><br /></span>\n"; The second problem: If you add an enter in the textarea and add the message, it will be fine, but if you add a second message, the first part before the linebreak of the first will be gone. Very strange. If anyone could help me with one of these problems I woul really appreciate it since I am out of ideas to solve this. Both problems are problems with linebreaks! Thanks Complete code: <?php $titel = 'agenda'; $header = '<link rel="stylesheet" type="text/css" href="agenda.css" />'; $tekstveld = '<form action="agenda.php" method="post"> <p><input name="naam" id="naam" type="text" maxlength="50"></input></p> <p><textarea name="boodschap" id="boodschap"></textarea></p> <input type="submit" value="Toevoegen" /> </form>'; $url = 'boodschappen.txt'; if((strlen($_POST['naam'])>=2) && (strlen($_POST['boodschap'])>=2)) { $naam = $_POST['naam']; $boodschap = nl2br($_POST['boodschap']); $id = date('ymdHis'); $datum = date('__ H:i __ l F j __ o'); $nieuw = "<span id=\"$id\">" . '<p class="naam">' . $naam . '</p><p class="boodschap">' . $boodschap . '</p>' . '<p class="datum">' . $datum . " || <a href=\"agenda.php?actie=verwijderen&id=$id\">verwijderen</a></p><br /></span>\n"; } if(file_exists($url)) { $boodschappen = fopen($url,'r'); $origineel = fgets($boodschappen); fclose($boodschappen); unlink($url); if($_GET['actie']=='verwijderen') { $id = $_GET['id']; $origineel = preg_replace ("/<span id=\"$id\">.*?<\/span>\n/",'',$origineel); $nieuw = ''; } $boodschappen = fopen($url,'w'); $tekst = $nieuw . $origineel; fwrite($boodschappen,$tekst); fclose($boodschappen); } $inhoud = $tekst . $tekstveld; $bestand = 'agenda.html'; if(is_file($bestand)){ $template = file_get_contents($bestand); $template = str_replace('{titel}',$titel,$template); $template = str_replace('{header}',$header,$template); $template = str_replace('{inhoud}',$inhoud,$template); echo $template; } ?>
  6. Well i would not call it lazy when i've been searching for hours to find the answer and didn't. Thanks to the other person who responded and didn't call my issue lazy.
  7. Hello I've found a simple regex to replace the string beginning with '<span id="unique id">some text</span><span id="another unique id">some text</span><span id="another unique id">some text</span>' with 'hello'. $original = preg_replace ("/<span id=\"$id\">(.*)<\/span>/",'hello',$string); The problem now is that the regex stops at the last '</span>' tag so my hole string get replaced by 'hello' but I only want to replace the string from the beginning '<span>' tag with unique id to the FIRST end '</span>' tag, not the last. How can I solve this? Thanks, Indigo
×
×
  • 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.