Jump to content

phpian

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

About phpian

  • Birthday 10/04/1982

Profile Information

  • Gender
    Male
  • Location
    Scotland

phpian's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The code only pulls down one row of data from the database. I don't know what you mean when you say "it's showing all the data from a column"
  2. I dont think it's the radio button. The value of the radio buttons should be appened onto the end of an array.
  3. so each element of $csv should itself be an array... $csv => array ( 0 => array( "love1", "love2", "love3", "love4", "addtext" ) ); somehow you've got a boolean in there $csv => array ( 0 => true ); I don't know how this happened. The code should always populate $csv with arrays. Can you try to debug it and see where $csv[] is assigned a boolean instead?
  4. There isn't anything wrong with line 51 in the code you posted but I'm quite sure that this is because the formatting has been messed up. There are lots of extra line breaks in the code you posted. If you run that code, I would actually expect you to hit an error on line 12 the chat support button) . However, if this script is formatted correctly for you, I don't think you need to do anything to it - so revert any changes you have made. If you open up the config.php or _settings.php you may see some settings there for connecting to your database. There is already code there for getting the data out of the table and updating it with what the user enters.
  5. $row is an array representing the row of data from a table. $row['field3'] is the data stored in column 'field3' in that row.
  6. Can you post your source code?
  7. There aren't 51 lines in the code I posted. Please provide more information of your problem.
  8. You can get a good introduction to PHP and MySQL on W3Schools. There are many ways to do it but this should get you started. <?php //make a connection to your database server $con = mysql_connect("localhost","peter","abc123"); //if you weren't able to connect to the database then stop here if (!$con) die('Could not connect: ' . mysql_error()); //otherwise select the database you want to use mysql_select_db("my_db", $con); //write a query $result = mysql_query("SELECT * FROM table"); //loop through the results while($row = mysql_fetch_array($result)) { echo $row['field1']; } mysql_close($con); ?> Hope this helps
  9. I use something called gettext. It is able to deal with the scenarios you have described. Basically, whenever you output a line that requires translating, you use the _("my text goes here") function. Then you are able to scan the source code which will generate a list of phrases that need translated. It can also deal with dynamic phrases that may be singular or plural. $num = 5; sprintf(ngettext("At the moment there is only %d table available", "At the moment there are %d tables available", $num), $num);
  10. Hi Bazazu, Sorry for the delay. I tried to run your code and finally realised what was going on. As was mentioned earlier, the normal structure of a CSV file is that each record set is on a new line. You are trying to append each value onto the end of existing rows so it does take a little bit more manipulating to get it the way you want. Basically, there was a problem with using fgets(). This just looks at each line individually and won't handle CSV structure when the values themselves contain new lines. Luckily, there is another function we can use to read the data correctly - fgetcsv(). This takes parameters to state how the fields are split up and enclosed. I have rewritten the code and commented it so you should be able to follow along. <?php //saving record in a text file if ($_POST) { $filename = "info.csv"; // array to store each line of our csv file $csv = array(); // Let's store this as an array so we can loop through it $fields = array("love1", "love2", "love3", "love4", "addtext"); // try to open our file $fh = fopen($filename, "r"); if ($fh) { // if we did manage to open it while (!feof($fh)) { // read the contents line by line // csv format needs to be comma separated enclosed with " $line = fgetcsv($fh, 1024, ',', '"'); // and store the contents in our array $csv[] = $line; } } else { // the file didnt exist so we need to add our field names // as the first element on each line foreach ($fields as $i => $field) { $csv[$i][] = $field; } } // we're done reading the contents fclose($fh); // add the new fields to the array foreach ($fields as $i => $field) { // double up any " in our fields so they remain enclosed $csv[$i][] = str_replace('"', '""', $_POST[$field]); } // open our file for writing $fh = fopen($filename, "w+"); if (!$fh) die("Cannot open file {$filename} for writing"); // write each element in our array to a newline in the file foreach ($csv as $row) fputcsv($fh, $row, ',', '"'); //we're all done fclose($fh); echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>thanx</font></p>"); } Hope this helps.
  11. maybe this could help http://dragan.yourtree.org/code/canvas-3d-graph/
  12. If a checkbox is ticked when the page is submitted it will have a value of "on", which is not an acceptable entry in your database. You need to change this to 1. $records[channel_protected] = ($postData[privateurlcheck]) ? 1 : 0; So if $postData[privateurlcheck] evaluates to true, it will set $records[channel_protected] to 1. if not, it will be set to 0. "on" evaluates to true. "" evaluates to false.
  13. Sorry, I missed the closing ) on the str_replace function. Try $string = '"' . $pfw_first_row[$i] . '","' . str_replace('"', '""', $_POST[$pfw_first_row[$i]]) . '"' . "\r\n"; and $string = rtrim($existing_file[$i], "\r\n") . ',"' . str_replace('"', '""', $_POST[$pfw_first_row[$i]]) . '"' . "\r\n"; If it still doesn't work, I'll get the script running here and post the code.
  14. Hi, Just use a JOIN in your SQL: SELECT plan.id, plan.plan_name, company.company_name FROM plan JOIN company ON company.id = plan.company_id ORDER BY plan.plan_name
×
×
  • 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.