Jump to content

BadGoat

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BadGoat's Achievements

Member

Member (2/5)

0

Reputation

  1. Yay! I fixed it.. Here's what works! (was a problem with the syntax of the MySQL query) Thank you kindly for pointing me in the right direction <?PHP include ("../config.php"); echo' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <link rel=stylesheet href="../eve.css" type="text/css"> </head> <body>'; $input = $_POST['t_data']; //your post data here. $array = explode("\n", $input); foreach ($array as $value){ if ($value != null && $value != "" && $value != " " && $value != "\n" && $value != "\t" && $value != "\r"){ $array2 = explode(",", $value); $cola = mysql_real_escape_string($array2[0]); $colb = mysql_real_escape_string($array2[1]); echo 'column a is '.$cola.'<br />'; echo 'column b is '.$colb.'<br />'; $sql = "INSERT INTO etest VALUES ('$cola', '$colb')"; mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); } } ?>
  2. OK, been tinkering all day and night and still not having any luck.. I have tried: $sql = "INSERT INTO `etest`('$cola', '$colb') VALUES ('$cola', '$colb')"; and $sql = "INSERT INTO `etest`('$cola', '$colb')"; and $sql = "INSERT INTO `etest`('$cola', '$colb') VALUES ('$array2[0]', '$array2[1]')"; and various other attempts at getting the two numbers posted into the db.. The goal is to take the data from the first page, separate by comma and then insert into the data into the db. Help ???
  3. I can understand that but that defeats the purpose of just pasting the data into the textfield on the previous page.. (I think!) Would the VALUES portion have to be $array2[0] and $array2[1] instead?
  4. ok, I started small, to make sure I had it figured out before expanding it, and I am getting an error.. On the page where I can paste in the data to the textfield I type 1,1 and submit it. The error I get: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1', '1')' at line 1 Actual query: INSERT INTO `etest`('1', '1') Here's the code from the second page: <?PHP include ("../config.php"); echo' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body>'; $input = $_POST['t_data']; //your post data here. $array = explode("\n", $input); foreach ($array as $value){ if ($value != null && $value != "" && $value != " " && $value != "\n" && $value != "\t" && $value != "\r"){ $array2 = explode(",", $value); $cola = mysql_real_escape_string($array2[0]); $colb = mysql_real_escape_string($array2[1]); $sql = "INSERT INTO `etest`('$cola', '$colb')"; mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); } } echo $input; ?> Is there anything glaring as to why it errors out?
  5. Thank you for the replies! I've been reading on the PHP site about EXPLODE and I see (in theory) how to use it.. And I see in your example code how it is done, so I think that I can play around with it. One question that comes to mind early on though.. As the field that I paste the data into is a textarea field, would I need to do something like $text = nl2br($text); to preserve the line breaks between each row of data I am entering?
  6. Hello! Looking for pointers in how to enter comma separated lines of text into a db using a text field? The ideal would be to have a text box which I can paste large lumps of data into which would be inserted into a db line by line.. I don't know which concept I should be learning to do such a thing. Any guidance is much appreciated! (example of data which could be pasted into a text field for db insertion) 200005, Vegetable, Corn 200006, Vegetable, Peas 300001, Fruit, Apple 300002, Fruit, Banana 400004, Meat, Mutton 400005, Meat, Turkey
  7. I tried a handful of different syntaxes (I get them mixed up, still to this day) // write form results to file $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $myFile = "testFile.txt"; $page_number = $row['page_number']; $line_number = $row['line_number']; $deo_text = $row['deo_text']; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $row['page_number']); fclose($fh); It does not error out, but it does write a blank text file.
  8. Sorry for confusion That's correct, I want to save the output from this query to a text file.
  9. Hello! I am trying to save a MSSQL query to a text file, and having no luck. I've read tutorials on how to create a text file and how to write some text to it: $ourFileName = "test.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Heres line number 1!\n"; fwrite($fh, $stringData); $stringData = "Heres line number 2!\n"; fwrite($fh, $stringData); fclose($fh); And I have written the query which displays the information I want, but I am not sure how to implement the query into the text file creation. Query: $sqlquery = "SELECT text.*, text_text.* FROM text_text, text WHERE text_text.textid = text.textID AND text.textID = '".$row['textID']."' ORDER BY dep_text_id"; $queryresult = mssql_query($sqlquery) or die(" Could not execute mssql query !"); $row = mssql_fetch_row($queryresult); Looking for a bit of direction!
  10. Hello! Looking for a kick in the right direction... How would I go about nesting an if/else within an if/else? As an example, let's say I have a list of music groups, and by clicking one of them, a list of their albums is displayed. (this part I can do!) But I want a list of the songs associated with that album to be displayed below the album. Perhaps nesting an if/else within an if/else is not the answer? I have tinkered with some theoretical code, and the only time I have been able to return anything, it's a single wrong song in every other album list. Any help would be most appreciated. Here's a bit of code which I've successfully used to $sqlquery = "SELECT song.*, album.*group.* FROM song, album, group WHERE song.song_id = album.song_id AND album.group_id = group.group_id AND group.group_id = '$group_id' "; $queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !"); $row = mysql_fetch_row($queryresult); $album= $row[0]; $tdcount = 1; $numtd = 1; // number of cells per row echo ' '; mysql_data_seek($queryresult,0) ; while($row = mysql_fetch_array($queryresult)) { if ($tdcount == 1) echo ''.$row['album'],' '; if ($tdcount == $numtd) { echo "<br />"; $tdcount = 1; } else { $tdcount++; } }
  11. OK, I see that COUNT is the right choice. Now when I want to echo the count, is it this? echo count($citycount);
  12. Hi! I am trying to count the # of instances where an ID appears in a table. I have a city table where each city has an id and a region id, a region table where the region has an id. I want to be able to count the # of cities are in a region by id. Everything I've tried is either 0 or 4, no clue how I got 4, even though I verified that none of the regions had only 4 cities. Here's a bit of code, where I'd been trying to get it to work. <tr> <td>'.$row['region'].' contains '; $query1 = "SELECT SUM(region_id) AS totalcons FROM e_city WHERE region_id = '$region_id'"; $result = mysql_query($query1); $r = mysql_fetch_array($result); echo number_format($totalcons); echo' Cities.</td> </tr> Please point me in the right direction. Thanks!
  13. thorpe, diw_id={$row['diw_id']}' made all the difference in the world. With that, now the pop-up pops correctly with the data from my db. Thank you kindly!
  14. OK, going through my own code, I found I constructed the Java portion incorrectly. Now, echo"<a href=\"/edits/edit_status.php?diw_id=".$row[diw_id]."\" onClick=\"openPic('/edits/edit_status.php?diw_id='".$row[diw_id]."' size=small','pop','600','200'); return false\">[edit]</a></td> "; echo' The above gives me the correct data but the pop-up window functionality is not working. But if I do echo"<a href=\"/edits/edit_status.php?diw_id=".$row[diw_id]."\" onClick=\"openPic('/edits/edit_status.php?diw_id=".$row[diw_id]." size=small','pop','600','200'); return false\">[edit]</a></td> "; echo' instead, the pop-up functionality works, but the SQL data is not pulled.
×
×
  • 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.