smantscheff 265 Veteran Poster

Use two queries and bracket them into a transaction. That makes them from a logical and database point of view only one query in two chunks.
If you don't like that, use this inefficient solution:

UPDATE runquery.table1, runquery.table2 SET 
runquery.table1.`Column1` = if(itemid=3,(runquery.table2.`Col1`/runquery.table2.`Col2`*100),Column1),
runquery.table1.`Column2` = if(itemid=5,(runquery.table2.`Col1`/runquery.table2.`Col2`*100),Column2)
where runquery.table1.`Userids` = runquery.table2.`userid`;
smantscheff 265 Veteran Poster

What syntax error do you get? I assune it's because the column names in your query are bracketed in apostrophes, which the should not be. Try instead:

mysql_query ("INSERT INTO members(ID,Name,Surname,Phone,Email,Cemail,Username,Password,Cpassword)
	VALUES (NULL, '$Name','$Surname','$PhoneNo','$Email','$Cemail','$Username','$Password','$Cpassword'") or die (mysql_error());
smantscheff 265 Veteran Poster

How do you decide if a clause is needed in a query or not? If you have a rule for that, you can code it. But from your example this rule would have to rely on semantic knowledge rather on formal aspects of the query.

smantscheff 265 Veteran Poster

Bracket the whole order process with START TRANSACTION and COMMIT respectively ROLLBACK in case of any errors.

smantscheff 265 Veteran Poster

Maybe there is a mysql process still blocking the 3306 port. Restart the machine or kill this process (if you find it).
I don't know how close MacOS sticks to its ancestor linux. With linux the advice would be, look under /var/log/messages to find info as to why mysqld would not start.

smantscheff 265 Veteran Poster

1. What does "The last query doesn't work" mean? Do you get an error message or what?
2. Isolate your problem and present exactly the query which does not work and tell us in which way it doesn't work.
3. The clause "WHERE position <= $position AND position <= $position" is tautologic.
4. You use of "row" and "column" is confusing. Use the standard connotation.
5. Learn about the extract() function and apply it to your $_POST array.

smantscheff 265 Veteran Poster

You have to do it in several steps:
1) Check if there is a link with position 2 in the database.
2) If it is, UPDATE pages SET position=position+1 WHERE position >= 2 3) Now do your INSERT query

smantscheff 265 Veteran Poster
SELECT Course.courseID,courseName,courseInstructor,if(103 in (select studentID from studentLink s where studentID=103 and s.courseID=Course.courseID),103,NULL) as ID from Course;

There must be a better solution, but I'm too tired. Have a look at the EXISTS clause in select statements.

sas1ni69 commented: Solution worked perfectly and even provided a 2nd solution for further research. +0
debasisdas commented: this is why i like your posts +9
smantscheff 265 Veteran Poster

@debasisdas: You are not answering the question.
@gulbano: Yes there is - if you have database or web server logs which recorded the data entry time.

smantscheff 265 Veteran Poster

The mysql engine treats both queries as identical. Performance differences may be due to some additional parser activity, but these should not cost more than a few CPU cycles.

debasisdas commented: agree +9
smantscheff 265 Veteran Poster

I don't know a way to find out past insertion times from the database. If you keep detailed database or web server logs you might be able to identify log entries with database records.

smantscheff 265 Veteran Poster

MySQL has a date type called timestamp which records the time of the last update of a row. Add such a field to your table. This field changes with every update, though. If you want to keep the insertion time, use a datetime field and a trigger which updates this field with the value now() after insertion.

smantscheff 265 Veteran Poster

Use the one which you understand better. From the MySQL point of view it makes no difference.

smantscheff 265 Veteran Poster

go along those lines:

$q = mysql_query( 'select * from stock' );
while ($object = mysql_fetch_object($q)) {
  if (mycheck($object) < 3)
    echo "sell at once $object->ticker!";
}
smantscheff 265 Veteran Poster
CREATE PROCEDURE ClaimTotal
@Result varchar(50) OUTPUT 
as
select sum(total) into Result 
from claim
smantscheff 265 Veteran Poster

Your example is too scarce to give a general solution.
Do all your entires look like "xxx_yyy"? Do you want to search only the part before the underscore? Then use the mysql substr() and locate() function to isolate that part and apply the like operator on it.

smantscheff 265 Veteran Poster

Please mark this thread as solved.

smantscheff 265 Veteran Poster

It's quite unclear what you want. Do you want all records with a field_id=1? Then just select them. Or do you want all records in which a text field contains the string representation of the number 1? In this case use a regular expression:

select * from mytable wher field_id rlike '(^|[^0-9])1($|[^0-9])'

Also it looks like a flawed database design to have several id entries in one field.

smantscheff 265 Veteran Poster
SELECT id FROM members ORDER BY score desc LIMIT 6, 1
smantscheff 265 Veteran Poster

Glad to hear that. Please mark this thread as solved.
Move $prevProperty = $property; into the inner if clause (for systematical reasons only).

smantscheff 265 Veteran Poster

@debasidas: The question was not how to code a partition but about the behaviour in absence of such explicit coding - which I would also like to know.

smantscheff 265 Veteran Poster

MySQL wildcard comparison needs the "like" operator:

if ($_POST[district_zone] == "0") { $receivezone = "like '%'"; } else {$receivezone = "= " . $_POST[district_zone];} 
$query_rs_district = "SELECT property_districts.district_zone, property_districts.district_name FROM property_districts WHERE property_districts.district_zone '$receivezone' ";
smantscheff 265 Veteran Poster

Show your CREATE TABLE statements.
If properties and rooms are in a 1:n relation you should be able to build a query for your objectives with a simple join from properties to rooms:

select property.id, room.id from property, room where property.id=room.id_property

This returns only those properties which have rooms associated with them.

smantscheff 265 Veteran Poster

You're barking up the wrong tree. Try to build a query which contains all data to be displayed and then loop through it. Do not use 5 queries - it makes your code illegible.
And regarding your code style: avoid redundancies. If mysql_query() goes with "or die..." whereever it occurs then those two belong in a function:

function myquery($sql) { return mysql_query($sql) or die(mysql_error()); }
smantscheff 265 Veteran Poster

Try another interface than phpMyAdmin, e.g. command line mysql. I assume that phpMyAdmin twiddles your query. Look in the server log what the actual query is which the server complains about.

smantscheff 265 Veteran Poster

You have to establish a connection first with mysql_connect().
Try

$rst = mysql_query($sql) or die(mysql_error());

to learn more about the problem.

smantscheff 265 Veteran Poster

Yes, you need an index on any referenced field.

smantscheff 265 Veteran Poster

Make sure that you have an index for all search criteria. And combined indexes for combined search criteria. Let MySQL EXPLAIN your query to optimize it. Add more RAM to your server. Increase the key buffer and other cache variables in my.ini.

debasisdas commented: almost there +8
smantscheff 265 Veteran Poster

$pdf->Output() writes a PDF file. This cannot contain JavaScript. The browser will not understand your code.
For passing variables between scripts use sessions and the $_SESSION array.

smantscheff 265 Veteran Poster

Take a beginner's course in PHP/MySQL. There are plenty out there.

smantscheff 265 Veteran Poster

I assume that with "title" you refer to the contents of the h2 tag.


$text = '<div class="dealsListS">
<h2>contents</h2>
<div class="thumbWrapper">images</div>
</div>';

preg_match( '~<div class="dealsListS">\s*<h2>(.*?)</h2>\s*<div class="thumbWrapper">(.*?)</div>\s*</div>~is'
	, $text, $matches 
);
$title = $matches[1];
$thumbs = $matches[2];
smantscheff 265 Veteran Poster

You can use the group_concat() function:

SELECT code, COUNT( code ), group_concat(data) AS no_of_times
FROM testing_table
GROUP BY code
ORDER BY code
smantscheff 265 Veteran Poster

It is not clear which part you want eventually to match. Do you want to replace css classes?
The first three preg_match statements are better put in one single statement to clarify the code. But first tell us which part you want to have extracted.

smantscheff 265 Veteran Poster

Wouldn't it make your database more efficient if you stored the image file in the server and just stored the image's address in the database instead?

You don't make your database more efficient with not storing pictures in it. That is rubbish. You make it more efficient by good design and careful indexing. There are lots of good reasons to have images in the database, one being coding efficiency.
Your upload code is wrong. To load pictures into the database you have to upload them as a file with your $_POST array containing the file name. Then you can read it from the local server into a variable and feed it to the mysql server. Google for "PHP file upload".

smantscheff 265 Veteran Poster

What does "does not work" mean? If the function mysql_result() does not work in your installation, you might have to start with a new system.
With a closer look you might have noticed that I missed a parameter in mysql_result. Try mysql_result($result, $r, $i) , then my code should give you the desired array.

smantscheff 265 Veteran Poster

What do you mean with "partially upload"? Does part of them get into the database? Show the receiving script and the CREATE TABLE statements for the images table.

smantscheff 265 Veteran Poster

It is a question of code efficiency. You use functions 1) to avoid code repetitions and 2) to make the semantics clearer. If the function is only called one during initialization and you will not use the result at another place, don't store it in a property. If on the other hand the function will be called more than once it is good practice to store the result for re-usage, especially if this is a costly function.

smantscheff 265 Veteran Poster

I don't understand the problem. You know how you can get column names using mysql_field_name(). You also know how to get the field content using mysql_result. Put both together to create any array you want. For example (not tested):

for ($i = 0; $i < mysql_num_fields($result); $i++)
  $columnNames[] = mysql_field_name($result, $i);
for ($r = 0; $r < mysql_num_rows($result); $r++)
  for ($i = 0; $i < sizeof($columnNames); $i++)
    $myResultTable[$r][$columnNames[$i]] = mysql_result($r, $i);

It that's not what you want, how would your desired result look like?

smantscheff 265 Veteran Poster
SELECT CustomerName 
FROM Customer 
WHERE NOT (Customer.CustomerCode in 
(SELECT c.CustomerCode
 FROM Customer c, Movie m, Video v
 WHERE c.CustomerCode = v.CustomerSoldTo
 AND m.MovieCode = v.MovieCode
 AND m.Rating = 'R'
))
smantscheff 265 Veteran Poster

You got your quotes wrong.
Change

$query = "SELECT * FROM players WHERE UID='$uid';

to

$query = "SELECT * FROM players WHERE UID='$uid'";

And use a decent editor with syntax highlighting. I recommend EditPad++.

smantscheff 265 Veteran Poster

Try order by 0 + hour

smantscheff 265 Veteran Poster

Of course. With preg_replace you can synthesize any expressions which you could catch with preg_match. E.g. for formatting domain names, you could use:

echo preg_replace( '~([a-z]+://)?(([a-z0-9]+\.)?([a-z0-9]+\.)+([a-z]{2}[a-z]?[a-z]?))~s', '<a href="http://$2">$2</a>', $sample);
//Result: 1word <a href="http://www.domain.com">www.domain.com</a> no period <a href="http://domain.com">domain.com</a> period. <a href="http://domain.com">domain.com</a> what else? <a href="http://www.domain.com">www.domain.com</a>
smantscheff 265 Veteran Poster

You can include aggregate functions for the stores in you Group subquery.

SELECT tblpolicies.PolicyNumber
     , tblpolicies.StoreId
     , tblpolicies.ConsultantFullName
     , tblpolicies.DateReceived
     , tblpolicies.ClientFullName
     , tblpolicies.Comment
     , tblpolicies.Query
     , tblpolicies.PolicyStatus
     , tblpolicies.DateModified
     , Groups.GroupName
     , Groups.StoreName
     , Groups.StoreTarget
     , Groups.StoreManager
     , Groups.PortfolioName
     , Groups.StoreStatus
     , Groups.RepName
     , Groups.ProvinceName
     , Groups.NumberOfPolicies

  FROM tblpolicies
LEFT OUTER
  JOIN ( SELECT StoreId,
                StoreName, StoreManager, GroupName, StoreTarget, PortfolioName
                , StoreStatus, RepName, ProvinceName 
                , (SELECT count(*) FROM tblpolicies where StoreId = tblstores.StoreId) as NumberOfPolicies
           FROM tblstores
         GROUP
             BY StoreId ) AS Groups
    ON tblpolicies.StoreId = Groups.StoreId
WHERE DateReceived BETWEEN '2011-01-01' AND '2011-01-31'
 AND StoreStatus='ACTIVE' ORDER BY GroupName

For further help submit a complete test case with CREATE TABLE statements, INSERT statements for test data and the relevant queries.

smantscheff 265 Veteran Poster

Yes, if preg can identify elements it can also transform them to any standard. My code does not provide for some more exotic url forms like username/password elements, and it does not tackle the query string, if present. But with an additional bracket you can at least catch the standard subdomain, domain and top level domain parts:

preg_match_all( '~([a-z]+://)?(([a-z0-9]+\.)?([a-z0-9]+\.)+([a-z]{2}[a-z]?[a-z]?))~', $sample, $matches, PREG_SET_ORDER)

Array
(
    [0] => Array
        (
            [0] => [url]www.domain.com[/url]
            [1] =>
            [2] => [url]www.domain.com[/url]
            [3] => www.
            [4] => domain.
            [5] => com
        )

    [1] => Array
        (
            [0] => domain.com
            [1] =>
            [2] => domain.com
            [3] =>
            [4] => domain.
            [5] => com
        )

    [2] => Array
        (
            [0] => [url]http://domain.com[/url]
            [1] => http://
            [2] => domain.com
            [3] =>
            [4] => domain.
            [5] => com
        )

    [3] => Array
        (
            [0] => [url]http://www.domain.com[/url]
            [1] => http://
            [2] => [url]www.domain.com[/url]
            [3] => www.
            [4] => domain.
            [5] => com
        )

)
smantscheff 265 Veteran Poster

Look at the answer to your first post of this item.

smantscheff 265 Veteran Poster

0) Your select box has several HTML errors: name=linklabel='' should probably read name='linklabel' Put quotes around all attribute values in HTML.
1) Use the onclick event in JavaScript: <select onclick='document.test.submit()'...> or something like that - I don't know the necessary javascript by heart.
2) In edit_page.php you get the selected value of your list box as a post variable: $selected = $_POST['linklabel']; // now $selected contains the id of the selected option

smantscheff 265 Veteran Poster

If you submit your data in the form of a test case - that is as MySQL statements which can directly entered into the mysql command line interface reproducing your problem, as in my post http://www.daniweb.com/forums/post1492091.html#post1492091 - I'm willing to give it a try.

smantscheff 265 Veteran Poster

If you are learning PHP, that's fine. In real life I'd rather recommend the linux command line.
The sleep function in this context is rather a joke - I would not trust a PHP program running as a web server module to run longer than a few minutes.
To combine it with a database, learn about php and mysql. Set up a table for URL, search string and result and insert your findings with something like insert into mytable (url,searchstring,result) values ('$url','$searchstring','result');

smantscheff 265 Veteran Poster

It depends on how regular your input is. In your example, domain names consist of lower-char strings with dots in between with an optional protocol name:

$sample = " 1word www.domain.com no period domain.com period. http://domain.com what else? http://www.domain.com ";
if (preg_match_all( '~([a-z]+://)?(([a-z0-9]+\.)+([a-z]{2}[a-z]?[a-z]?))~', $sample, $matches, PREG_SET_ORDER))
  print_r( $matches );
Array
(
    [0] => Array
        (
            [0] => [url]www.domain.com[/url]
            [1] =>
            [2] => [url]www.domain.com[/url]
            [3] => domain.
            [4] => com
        )

    [1] => Array
        (
            [0] => domain.com
            [1] =>
            [2] => domain.com
            [3] => domain.
            [4] => com
        )

    [2] => Array
        (
            [0] => [url]http://domain.com[/url]
            [1] => http://
            [2] => domain.com
            [3] => domain.
            [4] => com
        )

    [3] => Array
        (
            [0] => [url]http://www.domain.com[/url]
            [1] => http://
            [2] => [url]www.domain.com[/url]
            [3] => domain.
            [4] => com
        )

)

// hey ardav, what's a mook?

smantscheff 265 Veteran Poster

Use an INSERT query instead of an UPDATE query.