Solved

Append number to array

Posted on 2014-12-02
19
125 Views
Last Modified: 2014-12-04
I would like to add a number to this array:

<div class="stars" data-id="<?php echo $attorneysStuff['bizID'];?>2" data-stars="10" data-title="Pricing">

<?php schema($attorneysStuff['bizID'],10);?>

</div>


So it should be like this. In this case "2" is added, but it will not work this way:

[code]

<?php schema($attorneysStuff['bizID2'],10);?>

Open in new window

0
Comment
Question by:seopti
  • 7
  • 7
  • 2
  • +1
19 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40477135
Whats the error - there is nothing wrong with the code
0
 

Author Comment

by:seopti
ID: 40477169
The problem with the code is, there is no bizID2, there is only a bizID.

So this will code will not append the number "2" to the bizID.

<?php echo $attorneysStuff['bizID2'];?> 

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40477193
Not following you - if it doesn't exist then why are you trying to access it or do you mean

<?php echo $attorneysStuff['bizID']."2";?>
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:seopti
ID: 40477302
Thank you but still looking for the solution of this:

<?php schema($attorneysStuff['bizID'],2,10);?>

bizID needs the element 2 added at the and, after this ,10
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477313
What is schema
0
 

Author Comment

by:seopti
ID: 40477332
schema is a function.

<?php schema('someItemID');      //print schema.org rich snippets
schema('someItemID',10);      //print schema.org rich snippets with 10 - as maximum possible rating

Usually I append a sub-id to the bizID like this:
<?php echo $attorneysStuff['bizID'];?>2

But in the case above I have to get the syntax for:
<?php schema($attorneysStuff['bizID'],2,10);?>

I'm trying this for hours but without any result.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477341
And whats the code?
You can't ask use to help you do something and not show the code
0
 

Author Comment

by:seopti
ID: 40477366
This is the code for the schema function:

 USAGE EXAMPLE (your_file.php):
   
   <?php
   
      include_once ('www.your_site.com/path_to/snippets.php');		//include snippets.php file
      
      $itemID='myItem';		//item ID for which rich snippets will be displayed
      
      //call one of the functions, depending on which rich snippets you already use in your project
      schema($itemID);		//(recommended)
      //microdata($itemID);
      //microformat($itemID);
      //PDFa($itemID);
      
   ?>
   
   
*/





//template for schema.org
function schema($item_id, $best=5, $round=null){
    $stats = getStats($item_id, $best, $round);			//get rating from DB
    
	//in case of any database related errors
	if($stats==0) {echo ' !Error! '; return;}
	
	//dont print snippet if item has less then 1 vote to avoid google error message
//	if($stats['votes']<1) {echo '<br />item has less then 1 vote'; return;}
	
	//markup template for scheme.org. Edit it as you like.  
	$template = <<< EOF
	
	
<div itemscope itemtype="http://schema.org/CreativeWork">
	<a itemprop="url" href="{$stats['url']}">
		<span itemprop="name">{$stats['title']}</span>
	</a> 
	<span itemprop="aggregateRating"	itemscope itemtype="http://schema.org/AggregateRating">
		<meta itemprop="worstRating" content = "0">
		<span itemprop="ratingValue">{$stats['average']}</span> 
		out of <span itemprop="bestRating">{$stats['best']}</span> 
		(based on <span itemprop="ratingCount">{$stats['votes']}</span> ratings)
	</span>

</div>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40477392
bizID needs the element 2 added at the and, after this ,10
Doesn't make sense
0
 
LVL 12

Expert Comment

by:tel2
ID: 40477441
> Doesn't make sense
I'm struggling with this use of the English language too, Gary.
A bit (or even a byte) more time spent in giving enough info and writing things clearly could save everyone a lot of time in the long run, IMHO.  It's fortunate the some experts are very patient, which is impressive considering what they get "paid".
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40477534
Let's try this.

1. Please show us the data you have for input - not the code, just the data.  If you want you can use var_dump() to print out the values of the data.

2. Please show us the output you want to get from the data.

With that information we can usually show you the exact code to achieve the result.
0
 
LVL 12

Expert Comment

by:tel2
ID: 40477833
You must be better than you even know, Ray.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40477840
0
 

Author Comment

by:seopti
ID: 40482164
Of course Rays question was the answer. His question helped me solving this problem.

The other posters complained they are underpaid and it maked no sense, Ray provided a question which led to a solution so where is the problem?
0
 

Author Comment

by:seopti
ID: 40482165
Maybe you should pay the experts more so they will not be that frustrated about solving questions, just a suggestion.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40482174
posters complained they are underpaid
No one complained about being underpaid, tel2's comment was sarcasm because we are not paid.
All experts on here do it of their own free will

Now care to explain how a question asking for the data is an answer.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40482180
Maybe you should pay the experts more...
Ha!  Yes please raise my salary from E-E by at least 10%.  So many questions are answered by just getting from the initial question to the SSCCE!
0
 

Author Comment

by:seopti
ID: 40482243
They don't pay you but I pay them. So you for sure have high morals if you help poor coding souls if you are not paid :)

No rellay, they really don't pay the experts, what a shame!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question