Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




MySQL Results Not Working So Hot


Ok. Here I am again....probably posing a question with a solution so easy that, after looking at it for an hour, I can't figure out. Ok. here's the deal. please review the code below. Looks simple enough, right?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
I Want To Alphabetize Results, ORDER BY Not Working...
I have a list of contacts I want spit out into a table... it does that fine, but I want to alphabetically order them by nickname in descending order... PHP Code:

Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.

I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:

MySQL Not Working For PHP 5
I have a fresh install of MySQL and PHP 5 but PHP is saying that the
mysql_connect isnt there...does anyone know how to fix this?

Working With Mysql
I have installed php on my server and can get the phpinfo page to display.
I have installed mysql 5 and I'm able to get into the database and create
data. I would like to be able to get php to pull the data. I have been
reading on the internet as to what I need to do in php and have created a
couple of pages. When I go to the page all I get is a blank screen - no
data from the database.

I edited my php.ini file to allow for mysql. I copied libmysql.dll to my
c:windowssystem32 directory. Is there anything else that I need to do to
make mysql and php work together?

MySql Session Not Working
This is my first time using php and sessions. I am trying to follow
what I recently read, but it isn't working as I was expecting. Please
tell me what I'm doing wrong?

I have defined my session handlers in a session handler include file,
sessions.php. This file calls session_set_save_handler() and also calls
session_start(). Each handler function operates correctly when I login
- the data is put into the session table.

After successful login, the user is redirected to /path/index.php, which
includes sessions.php. session_start() is called again, but the
$_SESSION global has no data.

I know the individual pieces of code are working properly, because at
one point in the process they individually worked. But when I put it
all together, it just keeps going back to the login page.



MySQL 'update' Not Working..
I'm setting up a website on which you have to pay for membership. I allow the user to register with an 'elec' field in the database as '0'. The 'elec' field is '0' when they haven't paid and '1' when they have.

I've tested it and the login/register scripts work fine but i cant get it to change 'elec' to '1'. I use a separate script to buy elec, as shown below. Code:

Mysql Check Not Working?
The login and everything used to work until I moved these down from above the header. I moved them below the header so that the error messages (if any while logging in) will be displayed within the body rather than at the top of the page where they're hard to be seen. Code:

MySQL Connect Not Working
mysql_connect("localhost","---myUsername---","---myPassword---");And yet, it won't let me connect and gives me errors. I don't think it's my username or password that is messing this up, I think it might be the localhost part. I don't know which port to use, or what to put there. So, I would appreciate it if somebody could tell me how to find out what to put, or what to put.

Also, I am using PHPMyAdmin, so if this does not work with mysql queries then please tell me and I will try to figure out how to download a new MySQL database.

Arrays Working With MySQL
How can I grab a certain field of a Multi-Dimensional Array using the ID. I have set for that Array? I just want to be able to create a simple function to do pretty much what this function does, but for an array. Code:

If/then Within MySQL Results List
I want to list job opportunities for a facility. If there are jobs in the database, I can list them without a problem. But if there are no jobs, I'd like to echo a line something like: "No jobs right now, come back later." But I can't get that line to echo. PHP Code:

Mysql Writing Results From 51 To 100
Can someone write me a mysql_query code which will get me results from 51 to 100 from $database?

Don't suggest me working with indexes, because i'm also deleting some rows (for example #1 is filled #2 is not, #3 is...)

Show Next Results Of MySQL DB
How do I get it so that php reads in the first 10 results out of a MySQL database. Then when Next or something is hit it displays the next 10 results and so on.

MySQL Results To Return Only One Value
For example, I have a column that has three different values, 1, 2, & 3. In the database, there may be over 500+ entries with one of these values assigned to it. How can I get MySQL to return just 1, 2, & 3 only once rather than several hundred times.

Hyperlinked MySQL Results W/PHP
I was wondering how results to db querys have attached links to each individual result? I have a good grasp of basic PHP & MySQL, but don't understand how that works. For example, if you have a db of products, all with individual id #, how do you get one product from the query a <ahref>? Could someone explain?

Compiling MySQL Results
Does anyone know how to compare multiple results from a MySQL query? For example, I would like to query the database and collect all the results into a variable (perhaps $totalresults). Then, I would like to use a single statement to compare each of the results within $totalresults to the statement's conditions.

Mysql: How Do I Get The Rowcount Of The Results?
I want to execute some alternate code if the a query produces zero results, but I can't find any info on the web about how to get the number of rows in a mysql result.

Getting Results From MySQL Database In PHP
I am trying to write a php page which connects to a MySQL
Database which is supposed to get the results from a table within a
database and display the results in a table.

Below is the code that I am using:

Limit Mysql Results
I have a script which has a mysql query which returns 20 results - I want to add some validation so if my variable ($var) is empty, it only allows the user to select the first 5 results my code is: -

$sql = mysql_query("SELECT * FROM greetingcards_cards WHERE category='$cat' LIMIT $from, $max_results");
while($row = mysql_fetch_array($sql)){   
        $image = $row['url'];
       $cardid = $row['cardid'];
        echo "<br><img src="$image" /><br><a href="?function=sendmessage&cardid=$cardid">Pick this card</a><br>";}

I want it so that if the variable is empty, instead of displaying "Pick this card" it displays - "You must register to pick this card" and have a different hyperlink Is this type of validation possible? if so how is it done?

PHP MySQL Order Results
I'm using:

  $sql = "SELECT * from $myTable ORDER BY `points` DESC LIMIT 5";
in a whileloop to display the top five scorers but would like to put their position next to the results (eg, 1, 2, 3, 4 and 5)

Is there an easy way to do this?

Convert MySQL Results To XML
I just got Dreamweaver CS3, and I love the built in SPRY framework. It allows you to create web applications that use a table listing, and details listing very quickly. Unfortunately the only data the SPRY framework can accept is XML. Is there a built in function to convert from a $row result from MySQL to XML? Code:

Mysql Results - Ordering Them.
i need an mysql query to rank the results, like SELECT field FROM table and to order them greatest to least by the value of a different field. 

Mysql Results Pagination
I have a php code to split the results of a sql query over pages taht works great... But I need to add some feature, I need to add that if there are more than * pages it shows me "..." instead of the hole numbers of pages.. Code:

Sum All Of My MySQL Integer Results?
I have a bunch of rows, and for each row, the column "rating" has a number from 1-5. I need to add all of these together, so like if there were 3 rows with 5 for rating, it would return 15. If it's possible to do it with an SQL statement, I'll like it to average them.

Splitting MySQL Results
So I have a database, and I want to split the results into 2 columns. I don't want to alternate them, but have the first half in the left column, and the second half in the right column. How can I handle this so that it does it automatically no matter what number of entries (and so that if it's an odd number, the one overflow is on the left).

Image From MySQL Database Not Working
<?php
include 'dbinc.php'
$result = mysql_query("SELECT image,mime_type FROM photos WHERE
image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error());
if ($row = mysql_fetch_assoc($result)) {
$ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png');
header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
header("Content-Type: $row[mime_type]");
header("Content-Disposition: inline;
$_GET[id].".$ext[$row['mime_type']]);
echo "
".stripslashes($row['image']);
}
mysql_free_result($result);
?>

what am I doing wrong? I don't get an image. I've seen thumbnail stuff. I
don't want a thumbnail (that code didn't work either for some reason).

MySQL Multiple Tables / Results
I would like to perform multiple queries to a MySQL database and have all
the results in 1 result set.

Parsing PHP Code In MySQL Results Set?
I have a PHP script that pulls content from an MySQL database and returns a result set.

Is there a way I can put PHP code within a field in the database and have that code parsed as PHP code on returning a results set? If possible, I want just one field of the database parsed for PHP code. The results set is return as a straight result, not within a loop. Just inserting the <? PHP code thus ?> returns that as sources code not parsed.

Populating Array With Mysql Results
I'm returning a result set of one field in a table, and want to populate an array with the results. I can't for the life of me figure out a simple way to do this without using mysql_fetch_array() to cycle through the results, append that to a var, then explode that into a var and pass that. PHP Code:

MySql - Outputting Results In Groups
I want to output mysql data by groups (states). However each time php/mysql comes to a new state in the results I want it to print the state name before putting the results. Does php have some sort of memory function to recognize when the state has changed?

Split Mysql Results Into Two Columns
Trying to develop php catalog, but can't split the results into two columns, PHPcode:        

Mysql Results Output Problem
I trying to set up some subdomains and I'm at the early stages of just testing the the thing . I have set up a small test DB, with the following fields, company, id, url.

I have also set up a test page to see if the output corresponds with the subdomain name. If the domain exists the result with echo "domain exists" if not it will output "does not exist". But the page just says "does not exist" all the time even though the domains are set up.here's the code:

Exploding Results Of Mysql Query
I have a table with times and dates listed like this:

0000-00-00 00:00:00
2003-09-20 20:26:22
etc
etc

What I want is to query the DB for the field (matchdate) and then get it to explode the ' ' to give jsut the date for me and then put it into a dropdown in a loop. this may sound easy but i too sleepy to work it out and searching aint good.

Store Mysql Results Into An Array
i just started using php. i've used it before as a maintainer. fun stuff. well now i'm the writer. i want to abstract all the DB commands away from myself and all other developers. so i'm writing a function to query the php database from all users of the database and store them into an array as a return value so that i can seperate my database code from my html creation code.

1. is there a way to put all my database functions into a php file and include that file into all my other php pages? similiarly to a #include in C++ or a import package name in Java?

2. my code to run down the fetched results and store them into an array doesn't seem to be working the way i want it to. if i print out the results from the mysql returned fetch the data is fine. however the array seems to print out "Array[elementnumber]" instead of the value. Code:

Mysql Results <-- Previous Row, And Next Row, Showing Next Ok
I query a database and return a result on the column "reference".
There might be 7 listings. Each row is displayed in a table, with
links through to a detail page. I am working on having a "previous"
record and a "next" record link on the detail page.

This code below works, for the "next" record, by searching the values
in the array $myarray for the variable $ref. It then returns the key
value and the key value, as a number, is deducted by one and plus'd by
one to give me the previous row and the next row.

Returning the value of the next row works a treat, but for some reason
the previous row, deduct 1, while it echoes a value to screen, doesn't
work.

This is the code:

(query database and then:)
//$ref is a variable carried into the page

$num_rows = mysql_num_rows($result2);

$i=0;
while ($i < $num_rows) {
$next=mysql_result($result2,$i,"reference");

++$i;

$myarray = array("$i"=>"$next");
foreach($myarray as $key=>$value) {
if ($value == "$ref"){

$b=($key);
$c=($key+1);
$a=($key-1);

}}

if ($a == "0") {
echo "No Preceding Record";

} else {
if ($key == "$a") echo "<a
href=../detail/index.php?name=$value>Previous Record</a>";
}

if ($key == "$b") echo "This is the current Record";

if ($num_rows < $c) {
echo "Records End";
} else {
if ($key == "$c") echo "<a href=../detail/index.php?name=$value>Next
Record</a>";
}
}

} else {

JOIN Table Results W/MySQL
I have a query with a simple JOIN.

For example:

SELECT * FROM Companies
INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID

The query returns all fields from both Companies AND CompanyTypes. I would
like all fields from Companies only.

Counting Results From A Mysql Database
I want to know how many results throw a query in order to know if they have reached a limit.I.E.

$sql = mysql_query ("select * from classifieds where user='$username'");
while ($row = mysql_fetch_array($sql)){}

I want to check lets say that only 10 classifieds per  'username' can be created. If ten or more classifieds are in the database for that 'username' then show error message.

Alternating Row Colors With MySQL Results
Is there any way i could make a image for the alternating row colors instead of a strait bold color, for instance:

$color1 = "#CCFFCC";
$color2 = "#BFD8BC";

Would there be anyway to link an image in there? I have tried it this way:

$color1 = "<img src='..style1.jpg'>";
$color2 = "<img src='..style2.jpg'>";

How Can I Arrange Results Alphabetically In MySQL
I am using this code to retrieve names from the databse

$q = "SELECT * FROM
names
ORDER BY date DESC
LIMIT 5;";

How can i arrange names alphabetically

MySQL Query Not Returning All Results
I have a user table in the DB, for example:

+---------+----------------+-------------------+
|     uid     |     username     |       firstname       |
|----------+----------------+------------------+
|       1     |       cobby        |       Andrew          |
|       2     |       admini        |     test-account    |
+---------+-----------------+------------------+

If, in phpMyAdmin, I query:
   SELECT `username` FROM `users`;

It will return results correctly (cobby and admini, respectively).
But if I make a simple PHP script, such as:

<?php

mysql_connect('localhost', 'cobby', 'dbpass');
mysql_select_db('testdb');

$query  = mysql_query('SELECT `username` FROM `users`');
print_r(mysql_fetch_assoc($query));

?>

It only returns:
Array ( [username] => admini )

Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.

Mysql Dump Results In Blankfile
I am trying to get my script working to back up a mysql database. Everything works fine only the output results in a blank file. Code:

Merging Results From Two Mysql Databases
I have made two websites on seperate servers both with a database of their own.
They are identical but with different results in the databases. I want to make a page on one of the sites that will merge the information from both databases.

e.g.
site 1 has a list in date order
site 2 has a list in date order

I want site 1 to have the list merged together to form one big list but still be in date order. Also I want to be able to have the results of site 2 in a different font colour to site 1.

i.e.
Site 1 results

10th jan - something
15th jan - something else
19th jan - more

Site 2 results

11th jan - even more
13th jan - some more
16th jan - more stuff

Merged page

10th jan - something
11th jan - even more
13th jan - some more
15th jan - something else
16th jan - more stuff
19th jan - more

can anyone help with this?

Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table.

i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:

Displaying MySQL Results As URLs
I'm attempting to turn the results of a query into urls, yet I keep getting this error, "Parse error: syntax error, unexpected '<' in staff.php on line 190." I've coded and recoded this, yet for some reason I cannot get this error to go away. I know it's probably simple, but what am I missing? Code:

Working Combination Of PHP5, MySQL And OpenSSL
I'm trying to compile php 5.2.0 under FreeBSD 6. If I use the version of
OpenSSL that came installed with FreeBSD (0.97a) then it builds okay and
then segfaults on make install when it gets to installing pear. I tried
building with the latest OpenSSL and that causes make to fail with an error
about libmysql.a !!

The reason I am building with OpenSSL is because I need to access secure
sites (https://) via HTTP_Client and cURL. Without it cURL segfaults when I
attempt to access a secure site, and HTTP_Client returns "Malformed
response".

Does anyone know of a combination of MySQL, PHP5, and OpenSSL that builds,
installs, and functions correctly ?

Checking For Values In MySQL And Other Conditions Not Working?
I'm trying to redirect when testing for certain condidtions as shown
below. When the conditions are ture, it redirects, but still goes ahead and
processes the sql query. What am I doing wrong??? And then sometimes when
the conditions are correct, it doens't redirect. It appears to be very
inconsistent.

//Check for repeat name
$result = mysql_query("SELECT * FROM survey WHERE FirstName =
'".$FirstName."' AND LastName = '".$LastName."' ");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){header("location: ./oops.htm");};

//Check for repeat email
$result = mysql_query("SELECT * FROM survey WHERE EmailAddress =
'".$EmailAddress."' ");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){header("location: ./oops.htm");};

//Check for existance of first name, last name, and email
if(!$FirstName){header("location: ./oops.htm");};
if(!$LastName){header("location: ./oops.htm");};
if(!$EmailAddress){header("location: ./oops.htm");};

$newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')");
$result=mysql_query($newrecord);

Working With Substr To Get Paraphrased Data From MySQL
I have created a small PHP script that pulls the last 5 posts subject line from my message board and displays them on the main page of my site. The message board is made by WBB and the data is stored in a mySQL database.

What I would like to do is limit the amount of characters displayed on the main page to 20 per subject line. I have tried many ways by using the substr call, put I'm not having any success. Can anyone point me in the right direction as to where the substr call should be living in my script, and how it should be used? Code:

Connection To Mysql Working In Eclipse But Not On Apache?
I have installed apache, php5 and mysql on my laptop.

I write my code in eclipse and when I test it inside eclipse, the mysql
database connection is working, I can execute the script inside
eclipse. But when I put that same script into my htdocs on the apache
server running on the same laptop and access it using my browser, I get
a "Call to undefined function mysql_connect()" error message.

PEAR DB Not Working With Recently Upgraded MySQL 4.1
I recently upgraded from MySQL 3.23 to 4.1. Now db is not working properly.
I'd very much like your help in solving this issue!

Here's the code I used to test it:

require_once 'DB.php'
$db =&
DB::connect('mysql://user:password@localhost/dbname');
if (PEAR::isError($db)) {
die($db->getMessage());
}
$res =& $db->query('SELECT * FROM table');
if (PEAR::isError($res)) {
die($res->getMessage());
}

The error message I get:
DB Error: insufficient permissions

I have this username in MySQL 4.1 set up in mysq.user in the old style (pre
MySQL 4.1) password. This user has no right in the user table and SELECT
rights in the db table for this dbname. This is the way it always worked in
the past.

This is different, I think, from my previous post about php not working with
MySQL 4.12 because I have that working now - php4.4.4 is workingon my
machine with MySQL 4.1 yet Pear DB is not.

I verified the password by UPDATE setting it using OLD_PASSWORD() and
flushing privileges.

Presenting MySQL Results In A Paged Format.
I am developing a classified ad script using php4 and MySQL. My problem is: I want to display only 10 results of a dB search on each page.

At the botton of the page, I'd like to add forward and back links so that people can go forwards and backwards through the search results, with each page showing 10 results.

Can anyone point me towards a pre-existing script or example I can learn from?


Copyright © 2005-08 www.BigResource.com, All rights reserved