Author Topic: From .ASP recordsets to .PHP  (Read 395 times)

0 Members and 1 Guest are viewing this topic.

Offline TapeGun007Topic starter

  • Enthusiast
  • Posts: 130
  • Gender: Male
    • View Profile
From .ASP recordsets to .PHP
« on: March 18, 2010, 11:53:05 PM »
I need help converting something very simple from ASP (classic).

Here is the ASP code:
Code: [Select]
<% DO While NOT recordset.EOF %>
<tr><td colspan="3">Posted On: <%=recordset("NewsDate") %></td></tr>
(Populate a table from Access Database here)
<%
Recordset.MoveNext
Loop
%>

Basically, instead of using SQL to access the db, I used a recordset.  Why?  Because this is a memo field that stores news information.  In the news memo field, it stores apostrophies, and quotation marks.  Thus, using SQL to retrieve that information causes a problem on output.

What is the PHP equivalent?

As a recap, I have a memo field that stores lots of text with apostrophies and quotes.  I need to be able to pull the information out of the memo field without using SQL.  How can I do this?


Offline The Little Guy

  • Freak!
  • Posts: 6,103
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: From .ASP recordsets to .PHP
« Reply #1 on: March 18, 2010, 11:58:59 PM »
This is using mysql:

Code: [Select]
<?php 
$sql 
mysql_query("SELECT * FROM tbl_name");
while(
$row mysql_fetch_array($sql)){ ?>

     <tr><td colspan="3">Posted On: <?=$row["NewsDate"]; ?></td></tr>
     (Populate a table from Access Database here)
<?php
}
?>
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline TapeGun007Topic starter

  • Enthusiast
  • Posts: 130
  • Gender: Male
    • View Profile
Re: From .ASP recordsets to .PHP
« Reply #2 on: March 19, 2010, 12:03:49 AM »
ARG,  I should've posted what I already have:

Code: [Select]
$result = mysql_query("SELECT * FROM News WHERE ShowNews='Yes' ORDER BY News.NewsDate DESC , News.NewsID DESC");
    while($row = mysql_fetch_array($result))
    {
echo "<tr><td background='images/news_header.gif' class='ContentWhite'>&nbsp;&nbsp;<b>".$row['NewsTitle']."<b></td><td background='images/news_date.gif'>".$row['NewsDate']."</td></tr>";
echo "<tr><td background='images/news_main.gif' colspan='2'>".$row['News']."</td></tr>";
echo "<tr><td colspan='2'><b>-".$row['NewsWriter']."</b></td></tr>";
}

This is the output that I get:
Code: [Select]
�The breath isn�t that important.�
�are you still reading? Good. Now let me explain my reasoning for saying such a blasphemous thing.

See those funny characters?  They are quotes and apostrophies stored in $row['News'].  This is why in .asp I used recordsets instead of SQL to pull that information from the memo field.
« Last Edit: March 19, 2010, 12:05:52 AM by TapeGun007 »

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: From .ASP recordsets to .PHP
« Reply #3 on: March 19, 2010, 12:17:14 AM »
Quote
See those funny characters?  They are quotes and apostrophies stored in $row['News'].  This is why in .asp I used recordsets instead of SQL to pull that information from the memo field.

A recordset is essentially the same thing as a result resource in php. Which is exactly what mysql_query() returns.

Offline The Little Guy

  • Freak!
  • Posts: 6,103
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: From .ASP recordsets to .PHP
« Reply #4 on: March 19, 2010, 12:35:42 AM »
how did you encode the values when you put them into the database?
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline TapeGun007Topic starter

  • Enthusiast
  • Posts: 130
  • Gender: Male
    • View Profile
Re: From .ASP recordsets to .PHP
« Reply #5 on: March 19, 2010, 12:46:04 AM »
In .asp (classic) I used this code:

Code: [Select]
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\db\Choir.mdb")
Set recordset = Server.CreateObject("ADODB.Recordset")
IF Request.QueryString("NewsID") <> "" THEN
intID = Request.QueryString("NewsID")
Recordset.Open "News", sConnString, 1,2,2
Recordset.Filter = "NewsID = '" & intID & "'"
Recordset("NewsDate") = Request.Form("fNewsDate")
Recordset("NewsTitle") = Request.Form("fNewsTitle")
Recordset("News") = Request.Form("fNews")
Recordset("NewsWriter") = Request.Form("fNewsWriter")
Recordset("ShowNews") = Request.Form("fShowNews")
sMessage = "News Article Succesfully Updated!"

Offline The Little Guy

  • Freak!
  • Posts: 6,103
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: From .ASP recordsets to .PHP
« Reply #6 on: March 19, 2010, 12:59:08 AM »
what "Collation" are you using for that field?
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting

Offline andrewgauger

  • Devotee
  • Posts: 600
  • Gender: Male
  • Failure is a step on the road to success
    • View Profile
    • Resume
Re: From .ASP recordsets to .PHP
« Reply #7 on: March 19, 2010, 01:00:41 AM »
Check your database to see if it is encoded there.  I believe the database has those characters stored.  It looks to me you went from access db to mssql and that might be where the strange encoding happened.  Look into a way to sanitize your stored data if it is encoded with those characters.   PHP handles both ' and " appropriately by encoding them with a "\".
PHP 5.3.2 | Apache 2.2.14 | MySQL 5.1.41 | Ubuntu 10.04
Developers of the modern age get no respect.  We are always the blunt of jokes, the first to blame, and people hardly talk to us.  I wouldn't trade it for the world.

Offline TapeGun007Topic starter

  • Enthusiast
  • Posts: 130
  • Gender: Male
    • View Profile
Re: From .ASP recordsets to .PHP
« Reply #8 on: March 19, 2010, 01:48:06 AM »
Collation is utf8_general_ci

Using MyPHPAdmin, I checked the data and cut and pasted right out of the db:

Quote
“The breath isn’t that important.”
<p>
…are you still reading? Good. Now let me explain my reasoning for saying such a blasphemous thing.

So... the data in there is fine.

Offline The Little Guy

  • Freak!
  • Posts: 6,103
  • Gender: Male
  • Jinkies!
    • View Profile
    • PHPSnips
Re: From .ASP recordsets to .PHP
« Reply #9 on: March 19, 2010, 01:52:27 AM »
I think your quotes are of the wrong format...

You have:
“ and ’
Try this:
" and '
phpLive - A powerful library that implements many common tasks to make php programming faster. Supports extensions and plugins. Current version: 1.0.0-Alpha
JPG to ASCII Converter | Advanced Image CAPTCHA | Simple User Login | Check If User Is Logged In
http://dreamhost.com (promo code: 8RN4)
$30 off 1 year of hosting
$40 off 2 years of hosting