Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:39:11+00:00 2026-06-11T20:39:11+00:00

I’m just learning MYSQL / PHP. I’m having trouble with a query, it’s working

  • 0

I’m just learning MYSQL / PHP. I’m having trouble with a query, it’s working in myphpadmin:

select `email`, count(*) as count
from `table`
where `date` = "open"
group by `email`
order by `email`

I can’t get it to work if I either write the mysql_query myself or use the php myphpadmin generates:

$sql = "select `email`, count(*) as count\
    . "from `table`\n"
    . "where `date` = \"open\"\n"
    . "group by `email`\n"
    . "order by `email`\n"
    . "";

The purpose is to query a three column table of EMAIL, DATE, EVENT – where EVENT could be “open” or “bounce” and count the number of times a person opened an email.

Here’s the rest of the file (I realize I should be using msqli, that’s next on my list to figure out….):

<?php


$db_host = '123';
$db_user = '123';
$db_pwd = '123';

$database = '';
$table = 'test';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");



sql = "select `email`, count(*) as count\n"
    . "from `table`\n"
    . "where `date` = \"open\"\n"
    . "group by `email`\n"
    . "order by `email`\n"
    . "";



// sending query
$result = mysql_query($sql);
if (!$result) {
    die("Query to show fields from table failed 2");
}



echo "<table border='1'>
<tr>
<th>email</th>
<th>event</th>
<th>date</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Email'] . "</td>";
  echo "<td>" . $row['event'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
   }

echo "</table>\n";




mysql_free_result($result);
?>

I just get the “Query to show fields from table failed 2” back – the query didn’t work

The ‘\n’ in your query – was generated by myphpadmin (when I use the “generate php code” feature

I have a connection to the database, I just changed the value assigned to those variable so I wouldn’t post them

I have the “$” in the $sql var in my file, just didn’t get it copied over here.

So,

When I replace this query with a simple one, it works fine, but when I try the more complected query, no luck. I assume it has to do with converting the mysql WHERE date = “open” into proper (escaped?) php….


I’m not sure what the procedure is when I sorta found my own problem = The biggest issue (of several). When I used the “generate PHP code” feature on myphpadmin it didn’t keep the capital “E” in Email from the name of the column in the table…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:39:12+00:00Added an answer on June 11, 2026 at 8:39 pm

    Those newline characters might be the problem…

    try

    $sql = "select email, count(*) as count from table where date=\"open\" group by email order by email";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.