Jump to content

From .ASP recordsets to .PHP


TapeGun007

Recommended Posts

I need help converting something very simple from ASP (classic).

 

Here is the ASP code:

<% 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?

 

 

Link to comment
Share on other sites

ARG,  I should've posted what I already have:

 

$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'>  <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:

�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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

In .asp (classic) I used this code:

 

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!"

Link to comment
Share on other sites

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 "\".

 

Link to comment
Share on other sites

Collation is utf8_general_ci

 

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

 

“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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.