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

  • Home
  • SEARCH
  • 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 3598512
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:15:05+00:00 2026-05-18T20:15:05+00:00

i’m trying for days to get this working.. but i still fail. <?php $province

  • 0

i’m trying for days to get this working.. but i still fail.

<?php
$province = $_POST['test'];
$dbhost = 'localhost';
$dbname = 'news';
$dblogin = 'root';
$dbpass = '';

function dbConnect() {
   global $dbhost;
   global $dbname;
   global $dblogin;
   global $dbpw;

   $db = mysql_connect($dbhost, $dblogin, $dbpw) or die("could not
connect to database: ".mysql_error());
   mysql_select_db($dbname) or die("could not select database");
   return $db;
}
function dbClose($db) {
   mysql_close($db);
}


// basis code ^^


$db = dbConnect();

$query = "SELECT title FROM news_google_us"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{

echo json_encode($row);

 ;}


?>

i get this as response:

{"title":"Obama and GOP in Deal on Tax Cuts - New York Times"}{"title":"WikiLeaks Founder Warns About More Dispatches - New York Times"}{"title":"S. Korea to make islands near N. Korea fortresses - Jerusalem Post"}{"title":"9th Circuit judges explore narrow routes to reinstate gay marriage - Los Angeles Times"}{"title":"Killing of Iranian Scientist Overshadows 6-Nation Nuclear Talks - BusinessWeek"}{"title":"Schwarzenegger proposal rebuffed - San Jose Mercury News"}{"title":"WikiLeaks list of 'critical' sites: Is it a 'menu for terrorists'? - Christian Science Monitor"}{"title":"Big moments in the Concorde's history - BusinessWeek"}{"title":"Citigroup Stake Is Sold for About $10.5 Billion as US Unwinds Investment - Bloomberg"}{"title":"Jets Vs. Patriots: New England In Full-On Kobra Kai Mode...No Mercy - SB Nation"}{"title":"Obama, GOP cut deal to extend tax cuts - USA Today"}

I use Jquery to get the data:

 $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {   
      alert(textStatus);
      alert(errorThrown);
      alert(XMLHttpRequest.responseText);
  }}); 

 $.getJSON('mysql-query.php', function(data) {
    alert(data);
 });

I’ve tried a stripped version

<?

$dsn = "mysql:host=localhost;dbname=news";
$username = "root";
$password = "";

$pdo = new PDO($dsn, $username, $password);

$rows = array();
if(isset($_GET['descrtiption'])) {
 $stmt = $pdo->prepare("SELECT description FROM news_BBC_sport WHERE name = ? ORDER BY description");
 //   $stmt = $pdo->prepare("SELECT variety FROM fruit WHERE name = ? ORDER BY variety");
    $stmt->execute(array($_GET['descrtiption']));
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo "<pre>";
print_r(phpinfo());
echo "</pre>";
}

echo json_encode($rows);
?>

tried this one

I’ve tried a stripped version

<?

$dsn = "mysql:host=localhost;dbname=news";
$username = "root";
$password = "";

$pdo = new PDO($dsn, $username, $password);

$rows = array();
if(isset($_GET['descrtiption'])) {
 $stmt = $pdo->prepare("SELECT description FROM news_BBC_sport WHERE name = ? ORDER BY description");
 //   $stmt = $pdo->prepare("SELECT variety FROM fruit WHERE name = ? ORDER BY variety");
    $stmt->execute(array($_GET['descrtiption']));
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo "<pre>";
print_r(phpinfo());
echo "</pre>";
}

echo json_encode($rows);
?>

tried this one

http://www.phpclasses.org/package/4369-PHP-Generate-JSON-representation-from-MySQL-queries.html

I’m using firebug to check what’s wrong. I get this:

parse error

syntax error JSON parse

(shows json data)

I’ve tried like everything, but i still get this error. I’m using a XAMPP server on OSX.

  • 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-05-18T20:15:06+00:00Added an answer on May 18, 2026 at 8:15 pm

    You first attempt is almost right, just don’t echo each row, collect the result then echo:

    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $rows[] = $row;
    }
    echo json_encode($rows);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.