
Mr Chris
Members-
Posts
336 -
Joined
-
Last visited
Never
Everything posted by Mr Chris
-
Hello All, I have two arrays. One called $number_array and one called $title_array. $number_array = (1,2,3,4); $title_array = ("Title One", "Title Two", "Title Three", "Title Four"); Now what I want to do is run through each of the arrays one by one each time I query my database, so for example the first time it would output the query and title as: //First time SELECT * FROM tbl WHERE something = 1 <optgroup label="Title One"> //Second time SELECT * FROM tbl WHERE something = 2 <optgroup label="Title Two"> //etc.. so here's my code: <? echo '<select id="class" class="selectbox" name="class">'; $number_array = (1,2,3,4); $title_array = ("Title One", "Title Two", "Title Three", "Title Four"); $result = mysql_query ('SELECT * FROM tbl WHERE something = ".$number_array."') or die ('Error: '.mysql_error ()); echo '<optgroup label="".$title_array."">'; while ($row = mysql_fetch_array($result)) { echo '<option value="'.$row['id'].'" class="'.$row['name'].'">'.strtoupper($row['name']).'</option>'; } echo '</optgroup>'; echo ' </select>'; ?> Anyone please help?
-
Many Thanks, I get no message, but get these errors: Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /var/www/*******/httpdocs/******.php on line 37 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /var/www/*******/httpdocs/******.php on line 38 Warning: Invalid argument supplied for foreach() argument supplied for foreach() in /var/www/*******/httpdocs/*********/list.php on line 19 So I may be being thick here, but what do I have to do to allow deletion?
-
Thanks id is an int values in MYSQL, however i've tried it without the '' and it still does not delete ie:
-
Hello All, Wondering if someone can help. I have a piece of code which I use on all data I post to my database which uses mysql_real_escape_string on all my forms for security purposes that I found on t'internet: if(!get_magic_quotes_gpc()){ $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_REQUEST = array_map('mysql_real_escape_string', $_REQUEST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } However, ever since i've installed this i'm having problems with other elements, such as deleting records from a MYSQL database like so: <?php $msg = ""; if(isset($_POST['Submit'])){ $total = $_POST['total']; $news_ids = $_POST['nws_id']; foreach($news_ids as $id){ mysql_query("DELETE FROM news WHERE news_id='$id'"); } $msg = count($news_ids) . " News Item(s) deleted!"; } $result = mysql_query("SELECT *, DATE_FORMAT(published, '%d-%m-%Y') as formatted_date from news order by news_id desc;"); $num = mysql_num_rows($result); $n = 0; ?> Yet if I delete the piece of code above code it works fine, but I don't understand why the above code effects this? Anyone plese help me understand? Thanks
-
Hi, say I have a query like so: foreach($_REQUEST['r'] as $position => $row) { $row = implode("', '",$row); $result = mysql_query("Insert into player_stats (position,shirt_number,player_id,goals,cards,substituted,used_sub,injury,season,report_id) values('$position','$row','$currentSeason','$report_id')"); } How do I print the results of that query to my Browser for each time? Thanks
-
Hello, Im trying to work out some code. On my site between Thursday 12th July and Sunday 15th July between the hours of 22:00 and 23:00 I want to display some code. I've done this so far, but am having trouble. Anyone please help? $the_date = date("H:i:s"); $timesep = explode(":",$the_date); // $hour = $timesep[0]; if (($the_date > 2010-08-12 && < 2010-08-15) && ($hour >= 22) && ($hour <= 23)) { //Code }
-
Working with OOP outputting dynamic content?
Mr Chris replied to Mr Chris's topic in PHP Coding Help
Thanks! -
Hello, I've kind of mastered the basics of working with OOP with regards to 'static' content thats not database driven, but now I want to make it database driven. So take this example below where I output a headline, picture and Opening Paragraph within a CSS box. Click here to view the example ...and here's the code it's made up of ?php Class NewsBox { private $cssbox; private $headline; private $image; private $opening_paragraph; function __construct($cssbox) { $this->cssbox = $cssbox; } function setData($headline,$image,$opening_paragraph) { $this->headline = $headline; $this->image = $image; $this->opening_paragraph = $opening_paragraph; } function getData() { $output = '<div class="'.$this->cssbox.'"> <h3>'.$this->headline.'</h3> <img style="float:right" src="'.$this->image.'"> <p>'.$this->opening_paragraph.'</p> </div>'; return $output; } } $box = new NewsBox("wrapper"); $box->setData("Headline","image.jpg","This is the Opening Paragraph"); //The Headline, the image and the opening paragraph echo $box->getData(); ?> ...and that's fine, however, what i'm really struggling to comprehend is using OOP to grab content dynamically? Say for example I wanted another three css boxes on that page with the latest headline, picture and Opening Paragraph in them called from a database which is in exactly the same format as my static data like so. How would I go about doing that dynamically with the example above? Thanks
-
Hello All, I have a quick question on getters and setters in the below classes. The classes below are exactly the same, return the same values, but named different methods? Now are these examples both an examples of getter and setter methods? <?php class Box { private $contents; public function setContents($contents) { $this->contents = $contents; } public function getContents() { return $this->contents; } } $box01 = new Box; $box01->setContents('I am contents of box01!'); echo $box01->getContents(); // Output: I am contents of box01! ?> <?php class Box { private $contents; public function produceContents($contents) { $this->contents = $contents; } public function outputContents() { return $this->contents; } } $box01 = new Box; $box01->produceContents('I am contents of box01!'); echo $box01->outputContents(); // Output: I am contents of box01! ?> Get methods don't have to start with the word get and set methods don't have to start with set right? The two classes above are exactly the same apart from the naming convensions. I think i'm getting confused with the magic method __get. That's totally different right? Is it best practice to use the naming convention setWhatever and getWhatever when dealing with objects? Thanks
-
Thanks!
-
Hello All, Hoping someone can kindly help. I'm looking to move any files from one directory (parsers) to another (complete). Now i've tried two ways <? /* Set the path details */ $path = '/home/*******/parsers/test/parse/'; //Directory which I read from $complete = '/home/*******/parsers/test/complete/'; //Directory which I wish to place into $dir = opendir($path); while (false !== ($file = readdir($dir))) { rename("$path/$file", "$complete/$file"); } ?> But this way errors: home/cfpdigi/*******/test/parse//.,/home/*******/parsers/test/complete//.) [function.rename]: Device or resource busy and this way... <? /* Set the path details */ $path = '/home/*******/parsers/test/parse/'; //Directory which I read from $complete = '/home/*******/parsers/test/complete/'; //Directory which I wish to place into $dir = opendir($path); rename("$path/$file", "$complete/$file"); ?> Moves file to 'complete' but then completely deletes the 'parse' folder, when I want the 'parse' folder to remain in place, but just have it's contents moved to 'complete'? Anyone help? Thanks
-
Thanks, but ENT_NOQUOTES will leave both double and single quotes unconverted. I want double quotes unconverted which is great, but single quote I dont.
-
Hello, I have a funtion which I run on a string to convert characters to their html eqivalent like so: $string = cleanInput("There's a big bad woolf"); //There& #38 ;s a big bad woolf Now this works great, but say I had the string $string = cleanInput("There's a big bad woolf here <a href=\"click.php\">here</a>"); That would convert the " to the html equavalent as well. How could I get around this please and say anywhere there is a <a href> link use the cleanInput function but anywhere else in the text string do? Thanks
-
Put the results of a while loop into a image?
Mr Chris replied to Mr Chris's topic in PHP Coding Help
Thanks! -
Hi, I have a simple while loop where I call out two sets of rows $name and $value. Basically what I want to do is take however many come out of this query and dynamically stick them in the image below But i'll never know how many items will be called from that while loop, it could be five, or it could be 50. Anyone please help <?php $SQL = "Select * from table"; $RESULT = mysql_query ($SQL) OR die(mysql_error()); while($ROW=mysql_fetch_assoc($RESULT)) { $name = $ROW['name']; $value = $ROW['value']; } //Want to take all the values from name and value from the while loop and stick them in a google chart like so. But won't know how may there are ?? */ echo '<img border="0" src="http://chart.apis.google.com/chart?cht=p3&chco=17186B,348017,CC0000&chd=t:$,'.$value.','.$value.','.$value.'&chs=500x200&chl='.$name.'|'.$name.'|'.$name.'" />'; ?>
-
Help with a join getting ONLY the latest results in the table?
Mr Chris posted a topic in MySQL Help
Hello All, I have a query which looks in two tables for data and performs a join and works great: SELECT DISTINCT dc.order_id, dc.id, dc.campaign_name, dc.campaign_start_date, dc.campaign_end_date, dc.salesperson, dc.ad_type, dws.order_id, dws.impressions, dws.clicks FROM cart_campaigns AS dc INNER JOIN cart_weekly_stats AS dws ON dc.order_id = dws.order_id AND dc.campaign_start_date = (SELECT MAX(campaign_start_date) FROM dart_weekly_stats WHERE order_id = dc.order_id) WHERE dc.salesperson = '10' ORDER BY dc.order_id DESC However, I just have one problem I simply want the result to output the LATEST row for each order_id, when as you can see in the below it outputs all the results, so I just want the highlighted latest ones returned that are both different order id's (the latest ones for that particular order_id)? Can anyone help as this has been winding me up all morning! Thanks -
Hello, Bit confused? Anyone tell me which is the better to use between: htmlspecialchars_decode AND html_entity_decode and also htmlspecialchars AND html_entities Seem to do the same things. What are the differences in each case and which in each case is the best to use as they seem to end in the same result? Thanks <? //Know html_entities & html_entity_decode can take 3 Parameters //And htmlspecialchars_decode & htmlspecialchars take 2 //In each case what is the best to use? // htmlspecialchars_decode AND html_entity_decode $string1 = "Jane & 'Tarzan'"; echo "Using htmlspecialchars_decode:" .htmlspecialchars_decode($string1, ENT_QUOTES)."<br />\n"; echo "Using html_entity_decode:" .html_entity_decode($string1,ENT_QUOTES)."<br />\n"; // htmlspecialchars AND html_entities $string2 = "Jane & 'Tarzan'"; echo "Using htmlentities:" .htmlentities($string2,ENT_QUOTES)."<br />\n"; echo "Using htmlspecialchars:" .htmlspecialchars($string2, ENT_QUOTES)."<br />\n"; ?>
-
Calculating the difference between rows in MYSQL using php?
Mr Chris replied to Mr Chris's topic in PHP Coding Help
Thanks -
Hello, I have a table with a number of records in it like this example, each with the same order_id However this is just an example, there could be three records with the same order_id or there could be 33. What I want to do using php is say if there is more than one record for an order_id work out the difference between the previous and the next row, as indicated on my skilfully drawn diagram between the two columns impressions and clicks :-) However, i'm not at all sure how to go about this as it has to be dynamic and as I say I will never know how many rows are in the database for each order_id? Can anyone please help or is this not possible? Thank you
-
Thanls. but that's insering no values now :-(
-
Thanks Guys: function cleanQuotes($string) { $replace_characters = array('#',"'"); $html_characters = array("","& #039;"); $cleanstring = str_replace($replace_characters,$html_characters,$string); return $cleanstring; } foreach ( $data as $line ) { $val = trim ($line); $arr = explode ("\t", $val); $val_new = cleanQuotes(implode ("','", $arr)); $query = "INSERT INTO parse_original (player1,player2) VALUES ('".$val_new."')"; print $query; mysql_query($query) or die(mysql_error()); } Outputting as: When it should be:
-
Thanks , Kinda tried that already using addslashes like mysql_real_escape_string but My query still then comes out as: INSERT INTO parse_original (player1,player2) VALUES (\'Timothy\',\'O\'Brien\');
-
Hello People, I am trying to grab the contents of a tab delimited file and put it in a MYSQL table. Now it's working fine apart from one thing. Say I have the tab delimited file i'm grabbing the contents of like so: foreach ( $data as $line ) { $val = trim ($line); $arr = explode ("\t", $val); $val_new = cleanQuotes(implode ("','", $arr)); $query = "INSERT INTO parse_original (player1,player2) VALUES ('".$val_new."')"; mysql_query($query) or die(mysql_error()); } Now the above is grabbing each of the contents like so 'Timothy', 'O'Brien' (With Quotes) and with the above the query will fail becauseof the 'O'Brien' So I have created a function called cleanQuotes that takes any quotes and converts it into into a html version (') But it's now this doing this: Can anyone help me keep the function i've written but only run that on the text within the quotes so it parses O'Brien as ?
-
Magic. Thank You