PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old February 16th, 2013, 04:34 PM
steve71 steve71 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 steve71 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 58 sec
Reputation Power: 0
php5 - Issues with Explode

I have long descriptions stored in the database. Until today I haven't had any issues with using the explode function to display text on the webpage.

I am noticing that if my descriptions are really long the array cuts off text.

For Example, this is what my array results look like using explode:

Array (
=> /path/to/url.php [1] => /image/path/image.jpg [2] => Title [3] => /image/path/image2.jpg [4] => This is the description can be hundreds of characters long, even thousands, [5] => Smaller Description [6] => 6 [7] => Yes )



However, when the description [4] is real long it seems to limit the number of characters to around 1000 total and it looks like this.


Array (
=> /path/to/url.php [1] => /image/path/image.jpg [2] => Title [3] => /image/path/image2.jpg [4] => This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description ) <--- Stops here and doesnt show [5], [6] and [7]


Anybody know what is causing this and how to resolve this issue?

I would prefer not to have to limit the number of characters in my description [4] field.

The data is stored in a field with the following characteristics: varchar(2000)


I have also verified that the data is still in the database (visually using phpmyadmin)

Any insights or ideas on how to overcome this issue would be appreciated.

Steve

Reply With Quote
Old February 19th, 2013, 07:13 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
can you replicate it in php? (post the source here)
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Reply With Quote
Old February 19th, 2013, 02:50 PM
IAmALlama IAmALlama is offline
Me
Click here for more information
 
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,290 IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level)IAmALlama User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 11 h 28 m 56 sec
Reputation Power: 10
there is nothing wrong with explode. it can handle much more than 1k characters (max would be memory dependent, not the function itself). Those appear to be print_r of the array. Print_r doesn't have a limitation on size either. Is there maybe a less that symbol (< )somewhere in the text that html is parsing as the open of an html tag that has no close? view the source of the page and check if you see the entire text that you were expecting. Other than that, can you post your php code so that we can check for errors and perhaps the full text of your example description that you are having problems with.

Reply With Quote
Old February 20th, 2013, 11:23 AM
steve71-2 steve71-2 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 steve71-2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 56 sec
Reputation Power: 0
For some reason, I wasn't able to login with my old account and emails are not getting to me, so I created a new one to get going.

So, here is my code: I didnt originally write it, but have been modifiying over the years.

This is the relevant part within the function.
$result = mysql_query("SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode");

if ( mysql_num_rows($result) == 0)
{
print 'Unable to get product information from database at this time. Please <a href="/contact/index.php">contact us</a> for information';
}
else
{
$row = mysql_fetch_array($result);
$productcode = $row['0'];
$fulldescr = $row['8'];
$prices = explode(',', $row['4']);
rsort($prices);

$quantity = explode(',', $row['5']);
$extras = explode('|', $row['6']);


sort($quantity);

print "<tr>\n";
print "<td>\n";
if ($link =='1')
{
print "<a href='".$extras[0]."'><img itemprop='image' src='".$extras[3]."' alt='".$extras[5]."'></a>";
}
else
{
print "<img itemprop='image' src='".$extras[3]."' alt='".$extras[5]."'>";
}
print "</td>\n";
print "<td><strong>\n";
if ($link == '1')
{
print "<a href='".$extras[0]."'><span itemprop='name'>".$extras[5]."</span></a>";
}
else
{
print $extras[5];
}
print "</strong><br />";
print "<span itemprop='description'>".$fulldescr."</span>";
print "</td>\n";


Here is a sample data within the $extra field that gets exploded.

$extras[0] = /bcc/xy100/humidity-player98765.php
$extras[1] = /images/brand/xy100-123.jpg
$extras[2] = LOBO Brand
$extras[3] = /images/small/xy100-123.jpg
$extras[4] = The XY100-123 is a beta jogger with an internal densor for measuring and recording temperature and humidity readings. The beta jogger has a -20C to 70C and 15% to 95% RH measurement range with 0.21C and 3.5% RH accuracy. The display shows current temperature and humidity readings, recording mode, battery level and alarm status. The XY100 Series of beta joggers has a user-replaceable battery, software-selectable sampling rate of 1 second to 18 hours and stores up to 84,650 measured readings before download to computer is necessary. Simply connect the USB cable (supplied with the LOBOnare SHO Software) to the USB Port on your Windows 7, Vista or XP PC Computer and the LOBOnare software will configure your data logger and download the data for analysis. LOBOnare SHO software is required (sold separately) for setup and download of recorded data. Data can be exported and graphed within the software.
$extras[5] = XY100 Humidity Beta Jogger with 375% Accuracy
$extras[6] = 6
$extras[7] = Yes


If add the following text "Data can be exported and graphed within the software." to $extras[4] only a partial of $extras[5] is displayed on the page (using the code above)


I actually dont use extras[4] on the page, but so it really isnt needed here. I use for something else but store it in the database.


Your input would be appreciated.


Steve

Reply With Quote
Old February 20th, 2013, 11:58 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
your query is working fine?

id break out this:

Code:
$result = mysql_query("SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode");


into:

Code:
$query = "SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode";
$result = mysql_query($query);


and echo $query to ensure the sql call is not returning -1.

a better check would be to use:

Code:
$count = mysql_num_rows($result);
if ( $count > 0)


instead of:

Code:
if ( mysql_num_rows($result) == 0)

Reply With Quote
Old February 20th, 2013, 01:19 PM
steve71-2 steve71-2 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 steve71-2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 56 sec
Reputation Power: 0
The query itself is working fine.

It is result in the $extras array that is not working correctly when there is lots of data.



Steve

Reply With Quote
Old February 21st, 2013, 10:09 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
have you checked your errors file?

Reply With Quote
Old February 21st, 2013, 04:27 PM
steve71-2 steve71-2 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 steve71-2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by DavidMR
have you checked your errors file?


Which errors file are you referring too?


It is not creating an error, it is simply chopping information off.



Steve

Reply With Quote
Old February 21st, 2013, 04:35 PM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,437 DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level)DavidMR User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Month 3 Days 20 h 56 m 48 sec
Reputation Power: 9
have you tried echo-ing $row['6'] ? to see if its in there?

Reply With Quote
Old February 24th, 2013, 08:22 PM
steve71-2 steve71-2 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 4 steve71-2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 56 sec
Reputation Power: 0
row[5] and row [6] are not there and row[4] is incomplete.

However, if I reduce the amount of characters in row[4] then row[5] and row [6] are there and row[4] is complete.



Steve

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - Issues with Explode


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap