-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
To show all the articles returned by your query you need to use a while loop passing mysql_fetch_array as the condition, Example while($rows = mysql_fetch_assoc($sql)) { echo '<p>' . $rows[$title]. '-'. $rows[$date]; echo '</br>'; echo '</br>'; echo $rows[$article] .'</p>'; } NOTE: You should update your code to use either PDO or MySQLi now. The mysql_* functions are deprecated meaning they are no longer supported and could be removed from future versions of PHP.
-
Either of the solution mogosselin posted should be working for you from how you described your problem. What! That is nonsense. An array key can be wrapped in single or double quotes doesn't matter which is used. Do you get any error messages? If you don't then I suggest your turn error reporting on. Either in your php.ini configuration or apply this to the very top of your code (after the opening PHP tag) ini_set('display_errors', 1); error_reporting(E_ALL);
-
To find why your query is failing you need to use $stmt->errorInfo() // if the prepared query failed, trigger an error if(!$stmt->execute()) { trigger_error('Update query failed: ' . $stmt->errorInfo(), E_USER_ERROR); }
-
I have downloaded the free zip file from that site you mention and ran 1D_test.php just fine and the barcode generator wizard also runs without issue. I cannot see why you are getting that output. Seems to me you have modified the code?
-
I need a php button to change background color
Ch0cu3r replied to bulldog11's topic in PHP Coding Help
Not the sort of thing PHP should be used for. Javascript would be better suited for this. But to answer your question. To generate a new colour every five button clicks you need to check when $_SESSION['counter'] becomes divisible by 5. When this is the case you'd generate a new background colour. NOTE: in order to maintain the current background colour you will need to save its current value to the session. You'd then get the background colour from the session on page load. Example code if($_SESSION['counter'] % 5 == 0) { // generate new background colour // save new background colour to the session } -
You'd use setcookie to set the cookie Then using isset to check if the cookie exists in the $_COOKIE superglobal. If the cookie exist you'd show the second image otherwise show the first image Read the documentation to the linked pages above, study the code examples to see how they are used. From the pseudo code below you show be able to implement what you are trying to do in PHP /*before any output*/ set the 'visited' cookie /* in your HTML page you'd have this if statement*/ if(isset cookie 'visited') { /*output second image*/ } else { /*output first image*/ }
-
Got great help here, but having trouble implementing?
Ch0cu3r replied to Izzy-B's topic in PHP Coding Help
I think the problem is with the query. You have table called events not calander. Make sure you referencing the correct table name in your query. $stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?'); At this point your code is correct. The problem is just making sure you are using the correct database credentials and the query is referencing the correct table and column names. -
Got great help here, but having trouble implementing?
Ch0cu3r replied to Izzy-B's topic in PHP Coding Help
What the hell... Why have you modified your code so much you only had to remove four bloody spaces from line 76! Revert your code back what you had posted here: http://forums.phpfreaks.com/topic/290477-got-great-help-here-but-having-trouble-implementing/?do=findComment&comment=1487954 Now remove the space on line 76. -
Got great help here, but having trouble implementing?
Ch0cu3r replied to Izzy-B's topic in PHP Coding Help
The error is caused by line 76 EOT; Remove the four spaces before EOT; The closing delimiter must not have any characters (including white space, expect a line break) before it. It must be on its own line starting from the very first column of next line -
Got great help here, but having trouble implementing?
Ch0cu3r replied to Izzy-B's topic in PHP Coding Help
Sorry I didn't copy the code over correctly. I left off the closing braces for the foreach and if statements Add the following on line 101 } // close foreach } // close if -
Got great help here, but having trouble implementing?
Ch0cu3r replied to Izzy-B's topic in PHP Coding Help
Hey, Izzy-B I helped you yesterday. You have implemented my suggestions incorrectly. Maybe I wasn't clear enough on what needed to go where. Currently you have just pasted the code I mentions from my post after one another, which has resulted in code duplication and this is why the numbers are appearing below your calendar. So first lets correct your code from yesterday. The code you posted above start of by deleting lines 86 through to 118. Next replace line 78 with the following (this includes the fix suggested by mac_gver above) echo " $d "; // construct the date, this will be used to check to if the key exists in the $entries array $dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d); // check if the key exists in the $entries array if(array_key_exists($dateKey, $entries)) { // for each event, list it in a seperate tool tip foreach($entries[$dateKey] as $entry) { echo '<div class="has-tooltip"> Event <span class="tooltip">'.$entry.'</span> </div>'; That was the only edits you need to do so far. Next your query is completely wrong and this is why Your query is not returning any results because your are asking it to return the data from the information field in the events table, problem is you do not have a field called information in your events table (according to the screenshot of the table structure you posted in your first post). The only fields you have in your events table is id, description and startdt. Referencing fields that do not exist in a table will result in an error. You can use the mysqli_error function to retrieve the error from MySQL. The next problem with your query is the WHERE clause. Again you are referencing a field called value which does not exist in your events table. And you are comparing it to the value of an undefined PHP variable called $startdt. This will produce an error from PHP and MySQL. SO delete these lines $port = ini_get("mysql.default_port"); echo "the port ". $port; //execute the SQL query and return records $result = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT information FROM events WHERE value='$startdt', 'description'"); //fetch tha data from the database while ($row = mysqli_fetch_array($result)) { echo $row{'startdt, description'}; } //close the connection ((is_null($___mysqli_res = mysqli_close($con))) ? false : $___mysqli_res); What you need the query to do is return all the events for the current year and month being shown by the calander, for example if you scroll the calender to September 2014 we only want the events for this date to be returned form the database. Your calendar stores the current calander year and month in the $currYear and $currMonth variables. We can pass the startdt field to MySQL's YEAR and MONTH date aggregate function and compare them to those variables in the WHERE clause so to only return the events that match the calender year and month Sounds complex, but it is not. Add the following $currMonth = sprintf('%02d',$currMonth); // pad currMonth with zero's // when using user input, always use prepared statements otherwise could lead to SQL injection attacks $stmt = $conn->prepare('SELECT startdt, description FROM events WHERE YEAR(startdt) = ? AND MONTH(startdt) = ?'); $stmt->bind_param('ii', $currYear, $currMonth); $stmt->execute(); After these lines in your code $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; Now what we need to get the results from the query and populate the $events array for use, we can do that by using this after $stmt->execute(); $stmt->bind_result($date, $description); $entries = array(); while ($stmt->fetch()) { $entries[$date][] = $description; } Make sure you remove the existing $entries array I told you to add yesterday. You should now find the calendar is listing the events stored in your database. -
What? You are expecting that code to return 7 for the month even with the first line is comment out? You do realise lines that are commented out are ignored. Uncomment the first line returns the correct result.
-
You need to change these lines $type = $xml->Food[$i][type]; $name = $xml->Food[$i]; so the values are returned as strings not objects $type = (string) $xml->Food[$i]['type']; $name = (string) $xml->Food[$i]; Also remove this from lines 12 & 25 $food->key = $type; $food is an array not an object so you cant set properties to an array. Remove them it is not needed.
-
How to download two mysql tables in same excel sheet using PHP
Ch0cu3r replied to Tje's topic in PHP Coding Help
For what you are trying to do, yes will need to use that PHPExcel class you just found to create separate worksheets for each table. In order for you to that you are first going to need to learn how to use the PHPExcel class. Documentation can be found here. Once you have learned how to use that class you should then be able to work out how to merge it with your existing code. Dont mean to be harsh but I/we are not going to write the code for you. If we wrote it for you will not learn anything. If are not bothered about learning and just want the code ASAP then we have a freelance forum, post a job offering there for someone to write the necessary code for you. -
Query and output data from same table in db
Ch0cu3r replied to phpbnoobb23's topic in PHP Coding Help
Your code has a lot of issues. So we'll start from scratch To retrieve a specific row from a table you need to use a WHERE clause in your query, eg $query = mysql_query("SELECT * FROM `file` WHERE name='filename to search' "); You'd replace filename to search with the the actual name of the file you want to retrieve the file size for. You could replace it with your $File_name variable. BUT this is very insecure, it will open your code up to SQL Injection attacks (if that wording is new to you then google it, learn about it and how to protect yourself). Instead you'd first need to sanitize $File_name so its value is safe to be used in a query. PHP does have a function called mysql_real_escape_string for doing just that (*see note below). So now your code for fetching file size for the chosen filename will now read as $File_name = mysql_real_escape_string($File_name); // sanitize $result = mysql_query("SELECT name, size FROM `file` WHERE name='$File_name' "); // use it in the query, fetch the file size for the file. Then to output the filesize you'd you'd do something like this if(mysql_num_rows($result)) { list($name, $size) = mysql_fetch_row($result); // populate variables with the file name and size echo "The file size for <i>$name</i> is <b>$size</b>"; // output info } else { echo 'Invalid filename given'; } NOTE: The mysql_* functions are deprecated, meaning they are no longer supported/maintained and could be removed from future versions of PHP. I would strongly advise you to convert your code over to PDO or MySQLi and use prepared queries when using user input within a query. -
So you want to add entries to the calendar that is assigned to a specific date. For example you have an entry for August 16 2014 that you want to list for that date You could stored all entries for the calendar in an formatted like so (later to be populated by results from your database or flat file [csv or xml etc]), example // calander entries. Use the date as the key (in YYYY/MM/DD format) $entries = array( '2014/8/16' => array( 'Text to be shown on August 16 2014', ), '2014/8/24' => array( 'First entry for August 24 2014', 'Second Entry for August 24 2014', ), '2014/12/25' => array( 'Xmas day!', ), ) Here I have used the dates (in YYYY/MM/DD format) as an array key, all events for that date will be stored in an sub array, in case a date has more than one event. The following code is responsible for listing the days in the month for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='padding: 0px;'" : ''; echo "<td class=\"$cl\" $st>\n"; echo "$d" ; echo "</td>\n"; } You'd add an if statement after echo "$d" ; to check if the current date being outputted for the calender exists in the $entries array, example // construct the date, this will be used to check to if the key exists in the $entries array $dateKey = "$currYear/$currMonth/$d"; // check if the key exists in the $entries array if(array_key_exists($dateKey, $entries)) { // for each event, list it in a seperate tool tip foreach($entries[$dateKey] as $entry) { echo '<div class="has-tooltip"> Event <span class="tooltip">'.$entry.'</span> </div>'; } }
-
How to download two mysql tables in same excel sheet using PHP
Ch0cu3r replied to Tje's topic in PHP Coding Help
Currently your code only has one query for extracting the data from one of your tables (regfarmer). To get the data from the second table you'd add a second query and process the results the same way as before // get data from second table. $select_table=mysql_query("select * from SECOUND_TABLE_NAME_HERE WHERE ffname='$usr'"); $rows = mysql_fetch_assoc($select_table); if ($rows) { getcsv(array_keys($rows)); } while($rows) { getcsv($rows); $rows = mysql_fetch_assoc($select_table); } -
Query and output data from same table in db
Ch0cu3r replied to phpbnoobb23's topic in PHP Coding Help
The code you posted, only lists files in a <datalist></datalist>. When and where do you want the filesize to be shown? When some selects a file from the datalist and submits the form? What code have you tried so far. -
forward-compatibility link (mod_rewrite)
Ch0cu3r replied to web_master's topic in Apache HTTP Server
list -
The value of $steam->user['onlineoffline'] is defined by this line 'onlineoffline' => $content['response']['players'][0]['personastate'] == 1 ? 'Online' : 'Offline', Here you are harding coding its value to Online when $content['response']['players'][0]['personastate'] is equal to 1 or Offline for any other value. So this line line echo "<br /><strong>Online:</strong> " . $steam->user['onlineoffline'] . " "; will only output Online or Offline, not the actual status message returned by your getOnlineStatus() method. That value is stored in $steam->user['status']
-
Need help creating a simple video file server
Ch0cu3r replied to chrisyroid's topic in PHP Coding Help
You can hand code them if you want, but its pointless having them as PHP files, just leave them as plain HTML file. This is awkward as you'll have many HTML files to edit for making changes the page layout etc. But yes if all the information is in a database (doesn't have to be SQL, you could do a flat file database in csv or xml format) then you could dynamically render the page using PHP by searching the database by filename (if unique) or full filepath. Which means you only need to edit one file in order add/update/remove information about a video. This still is not ideal though as one mistake in the flat file will most likely cause corruption/errors. A relational database such as MySQL will be ideal. Any way to change the file link, You need to do is edit this line (the href attribute) echo '<li><a href="?dir='.$dir.'&file='.$filename.'">'.$filename.'</a></li>'; So if you have a html file named as the same as the movie file you'd change it to this echo '<li><a href="'.$dir . '/' . $filename.'.html">'.$filename.'</a></li>'; But yea you should consider moving your video information to be stored in an SQL database. -
Need help creating a simple video file server
Ch0cu3r replied to chrisyroid's topic in PHP Coding Help
Yea, that's intentional for the moment because I didn't know what you wanted to happen when some clicks on the filename. Again you dont need separate php files for each video. You only need one. Could you explain how you are getting the information for each episode/video? Is it from a database? -
I know. That is what the OP needs to add in order to output 2 results per row. I then showed the OP how to add to it to their code in my post here. Psycho has also demonstrated the exact same principle too in his post above. Your code will work yes, but it is not necessary to have two calls to mysql_fetch_array(). This what I was saying when I quoted you earlier.
-
on the next iteration of the while loop. How a new table row is created is controlled by the following if statement (this is what I am referring to earlier when I said 'logic') // close and open table row every 2 cells, NOTE replace 2 below for how many columns you want to repeat horizontally before starting a new row if (++$i % 2 == 0) { echo "\n </tr>\n <tr>"; } ++$ increments $i by one on every iteration of the loop. It will then $i % 2 (meaning return the remainder of the division). If the results is zero output a new table row. Have you not seen code like this before? Its seems you are confused by this, try and apply it to one of your queries and see what you get.
-
I never said to use arrays. I was pointing out PravinS had the correct logic to use in a loop for outputting two columns per row. Your solution of fetching the next row within the loop was unnecessary.