Jump to content

Sigg

Members
  • Posts

    15
  • Joined

  • Last visited

Sigg's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Problem solved - there are 162 records; an import hadn't auto-incremented the id column value correctly, so id's 30-108 weren't there.
  2. Not sure what happened in my previous post. Changing the query to COUNT(*) gives the same 162 count. The storage-type is MyISAM.
  3. I don't see any null values - and the column I am trying to count (my primary, auto-incrementing column - "id"), is set to non-null. All of the other columns are set to NULL if there isn't a value, and they all appear to be filled-in correctly. However, I had attempted to import a .csv a week ago, and it didn't go well- I had to make adjustments. Everything is adjusted, and everything looks ok, but it's still giving an incorrect count. I tried to change the "COUNT(id)" to "COUNT(*)", and it is still giving the same 162 total. Thank you for your help!
  4. Table and database name are all working correctly, but when I browse the table in phpMyAdmin, I can see the 250 rows that I have entered already, but I have a sense that some were either originally entered or imported incorrectly. The data _looks_ ok now, but I wonder if there is some way I can diagnose the error.
  5. I should note that I get the same 162 result trying to COUNT any of the columns, not just "id".
  6. My table has 250 rows, but COUNT only seems to see 162 of them. In phpMyAdmin, for instance, there is a notice in the browse tab: "Showing rows 0-161 (162 total, Query took 0.0030 sec)". On one of my php pages, I get the same 162 result from this attempt to count the number of entries to my auto-incrementing "id" column : $result = mysql_query('SELECT COUNT(id) AS id_count FROM MyTable)'; Can anyone suggest the kinds of things I should check/adjust to understand why about 90 rows are not being counted? Many thanks in advance for any help anyone can offer.
  7. And just like that - it has come together - Thank you, all who have helped! And still there is so much more that I hope to do with this project. For starters, I'm having trouble setting more than one parameter in my query: $query="SELECT * FROM MyTable WHERE code='GGGGG' or 'HHHHH'"; What do I have wrong here?
  8. Well, I have the connection script working (success!). Now I'm trying to clean up the fact that I had php in both <td>s. My first attempt is giving me a new error. Here's the new page attempt: <table align="center" border=\"0"\ width=\"100%"\ cellpadding="20" > <tr> <td> <?php include('inc/req.php'); include('inc/bank.php'); if(isset($_GET['result']) && trim($_GET['result']) != ''){ $get_result = trim($_GET['result']); $query = "SELECT * FROM MyTable WHERE ref='" . mysql_real_escape_string($get_result) . "'"; $resource = mysql_query($query,$link); if(!$resource){ die('Could not get data: ' . mysql_error()); } while($result=mysql_fetch_assoc($resource)){ $ref = $result['ref']; //$title = $result['title']; echo "<img align='center' src='http://covers.openlibrary.org/b/isbn/".$ref."-L.jpg'/>"; } echo "</td><td>" //Line 85: $query = "SELECT * FROM MyTable WHERE ref='" . mysql_real_escape_string($get_result) . "'"; $resource=mysql_query($query,$link); echo " <table class=\"sortable\" align=\"center\" border=\"0\" width=\"100%\"> "; while($result=mysql_fetch_array($resource)) { echo "<tr><h2>".$result[1]." </h2></tr><tr><td><b>Author:</b></td><td>".$result[0]."</td></tr><tr><td><b>Location:</b></td><td>".$result[21]."</td></tr>"; } echo "<tr><td> </td></tr></table>"; mysql_close($link); } else { die('result is not set in url'); } ?> </td> </tr> </table> ...and here's the error I am receiving: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/content/.../book.php on line 85 I commented line 85 into the code above so you can see where there error is. Am I seeing a parse error because of missing punctuation, or is the punctuation correct, but something else is in the wrong place? Do I need to have the $_GET in there twice?
  9. That was going to be my next question! It is currently a mix. I assume the correct thing to do would be to use mysqli throughout, aye?
  10. I have it up above a bit, as: <?php $db_conx = mysqli_connect("xxxxx", "xxxxx", "xxxxx", "xxxxx"); if (mysqli_connect_errno()) { echo mysqli_connect_error(); exit(); } ?>
  11. I've placed the req.php file in a few places to make sure it can find it (!), and now I am seeing a different error: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/.../book.php on line 66 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/content/.../book.php on line 66 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/.../book.php on line 68 Could not get data: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) ...which tells me I must have something wrong here: (ln66, ln68 are here to show line numbers in the errors. "MyTable" is the actual table in my copy!) <?php require('req.php'); //check if result exists in url and is not blank if(isset($_GET['result']) && trim($_GET['result']) != ''){ $get_result = trim($_GET['result']);//use the trimmed result and create a variable (ln66) $query = "SELECT * FROM MyTable WHERE ref='" . mysql_real_escape_string($get_result) . "'"; (ln68) $resource = mysql_query($query,$link); if(!$resource){ die('Could not get data: ' . mysql_error()); } while($result=mysql_fetch_assoc($resource)){ $ref = $result['ref']; //$title = $result['title']; echo "<img align='center' src='http://covers.openlibrary.org/b/isbn/".$ref."-L.jpg'/>"; } mysql_close($link); } else { //show an error, redirect, anything you desire die('result is not set in url'); } ?> Do I need to have this somewhere? mysql_select_db("MyDatabase",$link) or die ("Cannot select the database"); Everything is working when I call the database from within the page, (with the above mysql_select_db), but I'm not having luck with referenced req.php yet...
  12. That's what I thought, and I've been trying all manner of variation on the path to try and get it right, but to no avail. I'll keep working at it.
  13. Success -- my many thanks! And now I'd like to try to import the connection script as recommended (...and change some of the wildcard queries... and revise with mysqli...) Here's my attempt at that in /inc/req.php: <?php $db_conx = mysqli_connect("xxxxx", "xxxxx", "xxxxx", "xxxxx"); if (mysqli_connect_errno()) { echo mysqli_connect_error(); exit(); } ?> ...and in my book.php page I have tried both: require('inc/req.php'); ...and: include('inc/req.php'); ...but I'm getting these errors, (using any of include, include_once, require, and require_once): Warning: include_once(inc/req.php) [function.include-once]: failed to open stream: No such file or directory in /home/content/(...etc) Warning: include_once() [function.include]: Failed opening 'inc/req.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/content/(...etc) Where should I have the require(); or the include(); line? Thank you, again, for any help.
  14. This is all enormously helpful - thank you! When I think it through again, I can see that the first section of the page probably doesn't need to make a server connection. It just needs to get the variable from the url, and pass it to the openlibrary api url. The second part of the page needs to make a server connection and sql query to return a number of variables about the book in question, like author, language, pages, etc. I worked with what you graciously posted, and got the second part working, but the first section isn't working. It gives me the error: ""Could not get data: Query was empty" Using: mysql_real_escape_string($get_result) ...is working in my second table td below, but not in the first, and I don't see what I am doing wrong: <table align="center" border=\"0"\ width=\"100%"\ cellpadding="20" > <tr> <td> <?php //check if result exists in url and is not blank if(isset($_GET['result']) && trim($_GET['result']) != ''){ $get_result = trim($_GET['result']);//use the trimmed result and create a variable $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $query-"SELECT * FROM MyTable WHERE ref='" . mysql_real_escape_string($get_result) . "'"; $resource = mysql_query($query,$link); if(!$resource){ die('Could not get data: ' . mysql_error()); } while($result=mysql_fetch_assoc($resource)){ $ref = $result['ref']; //$title = $result['title']; echo "<img align='center' src='http://covers.openlibrary.org/b/isbn/".$ref."-L.jpg'/>This"; } mysql_close($link); } else { //show an error, redirect, anything you desire die('result is not set in url'); } ?> </td> <td> <?php $link=mysql_connect("localhost", "mysql_user", "mysql_password") or die("Cannot connect to the database"); mysql_select_db("MyDatabase",$link) or die ("Cannot select the database"); $query="SELECT * FROM MyTable WHERE ref='" . mysql_real_escape_string($get_result) . "'"; $resource=mysql_query($query,$link); echo " <table class=\"sortable\" align=\"center\" border=\"0\" width=\"100%\"> "; while($result=mysql_fetch_array($resource)) { echo "<tr><h2>".$result[1]." </h2></tr><tr><td><b>Author:</b></td><td>".$result[8]."</td></tr><tr><td><b>Total Pages:</b></td><td>".$result[15]."</td></tr><tr><td><b>Publisher:</b></td><td>".$result[10]."</td></tr><tr><td><b>ISBN:</b></td><td>".$result[3]."</td></tr><tr><td><b>Binding:</b></td><td>".$result[12]."</td></tr><tr><td><b>Publication Year:</b> </td><td>".$result[9]."</td></tr><tr><td><b>Language:</b></td><td>".$result[16]."</td></tr><tr><td><b>Genre:</b></td><td>".$result[17]."</td></tr><tr><td><b>KML Code:</b></td><td>".$result[18]."</td></tr><tr><td><b>Id. #:</b></td><td>".$result[0]."</td></tr><tr><td><b>Location:</b></td><td>".$result[21]."</td></tr>"; } echo "<tr><td> </td></tr></table>"; ?> </td> </tr> </table> Thank you, again, for any help anyone can offer!
  15. I'm a beginner with php, but I have a few nifty things working, and I'm trying to enhance my project to do something at the next level. The project is a library database search tool, and I'm having trouble getting from the search results to the page which shows a record for an individual book. The search tool works well, and works a few different ways, so I feel I should be able to get this, but this is a first attempt. I'm stuck on where and how to use $_GET. If I understand what I need to do, it's something like this: My search results page has a link as part of the last column: My first question is, how do I parse this link in php so that it pulls the Id. number from the database, (so that "Link" points to /book.php?0140441638 as a uri? That column looks something like this: On the next page, (book.php) which should be the page which shows the information for the individual book, after connecting to my database I have $query="SELECT * FROM MyTable WHERE id='0140441638'". How would I go about passing the '0140441638' from the referring link? The next question is how to concatenate this with the openlibrary link in the screenshot -- so that it is passed like src='..//covers.openlibrary.org/b/isbn/**RESULT**-L.jpg' /> Thank you to anyone who can help me with this!
×
×
  • 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.