multiple links per row in mysql - php

I have a MySQL database in which each row represents an episode of a podcast. I would like to include show notes for each episode and therefore need to be able to extract multiple links per row via PHP.
What would be the best data field to achieve this? I'm thinking that including the links via a linked table may be the only way to do this, but if anybody knows a simpler way I'd love to hear about it.

I would definitely recommend using a new table (podcast_link) because the number of links per podcast is flexible. Adding a text field to the podcast table wouldn't be very efficient due to the parsing of the links when you want to display them.
This will also allow you to e.g. count the number of links per podcast, so you can display "Show related links (4)" and you can add more fields to the links, so that you don't only display the links, but also a title for the link. Especially going forward you might want to add more information per link.

explode() Function :
You have to save your links for example with this structure :
http:\\example.com\podcast01.mp3,http:\\example.com\podcast02.mp3,http:\\example.com\podcast03.mp3 in the database rows.
then when you want to extract them you can easily use explode() function with this way :
$links= $row['links']; // your links in row
$links_array = explode("," , $links);// now you have an array that you can easily access to each block of it.
for example :
echo ($links_array[0]);// output : http:\\example.com\podcast01.mp3
good luck

Related

PHPWord Prevent rows from the same table appearing on different pages

thanks for help with previous PHPWord issue. I have another.
I'm creating documents with tables where each table is basically used as a stylized container for a list of items. For example, in my case i have a collection of legal definitions. Each definition has a code, title, and textual description that appears in a table. So when there's multiple definitions, each definition has its own table, and appears like so:
and so on. Each table isnt really a table, its more i'm kind of hijacking tables to stylize my document. The problem is when I have a long list of items, invariably some of the tables will be split between pages where the top row of the table will be at the very bottom of the page and bottom row of the table will be at the very top of the next page, like so
This is very undesired. Is there any way to tell PHP word that "hey, if this table is going to be split between pages, just put the whole table on the next page" ??
I'm also using PDFmake for making pdf's and it has a pageBreakBefore function that can be used for exactly this purpose. I notice that paragraphs have a pageBreakBefore style which can force each pragraph to appear on a new page, but this isnt what i'm looking for. Is there some way i can maybe get into how PHPWord builds the document to put a conditional test in maybe?
Any input is greatly appreciated thanks.
I had the same problem .... and found the answer today in "normal" MsWord documentation. I found the equivalent in the phpWord doucmentation, tried it and it works:
In your paragraph formats, set 'keepNext' => true

Separate data from database into pages

This is my code:
$query="SELECT * from project where batch='$bach'" or die(mysql_error());
$var=mysql_query($query) or die(mysql_error());
if(mysql_num_rows($var)==0)
{
echo "No such batch exist.<br />";
}
while($arr=mysql_fetch_row($var))
{
echo $arr['batch'];
}
I am just displaying one field right now thats batch but there are 8 columns and many rows would be filled when user inputs the data.. This code will display the content on the same page making the page quite long. How can i split the data into various pages with html and php? A better example can be google which splits the search results into pages and with page numbers at the bottom.
Please chk this tutorial for php mysql pagination http://www.tutorialspoint.com/php/mysql_paging_php.htm .
I would personally recommend two things for you.
Create a router that will take a variable from url , like yoursite/list/11 , it will create a list , with eleventh set of your database values. Use mod_rewrite so you can have "pretty urls"
About PHP routing
You will need to create a function that will count your DB entries , and divide that number into page sets. Say One hundred entries equals ten pages. This will let you create that kind of menu that looks like 1,2,3....,9,10.
Another function which will retrieve the specific set of entries, and then pass it to whatever script runs your "list"
Since your question is not 'help me find error' but rather 'how to achieve this', I'm afraid I cannot offer more than basic logic of things.
Second thing i will recommend is avoiding mysql_ functions , because these are deprecated and will be removed from PHP.

php - find segments of similar text within a string with php

I am familiar with the similar_text() function in PHP but what I am trying to think of how to do is find potential links I could add in my content to other articles that I have.
What I want is to be able to scan through all my content in each post and find a segment of text in a post that is similar to a title of another post.
So lets say I have the following structure
$contentfromapost = "this is example text of the content in this article. It talks about things that people like to do for fun and vacation spots where they can do them all around the world"
$titleofpost1 = "Yellow cats are fun to throw in the snow"
$titleofpost2 = "Vacation Rentals in Fun parts of the world"
So my idea is to scan the first post content, then scan the titles of all my articles.
As you can see in my example $titleofpost2 has matching keywords to the $contentfromapost.
Then I would want to be able to grab the segment of text in $contentfromapost and send a link to that post with the similar title. I would maybe use anchor text "fun and vacation spots where they can do them all around the world" to link to that second post.
I want to build this to help me find other posts that I could link too within an article. Potentially I would like it to be able to automatically add the link with the section of text.
Anyways trying to see how I could structure this, any ideas would help
Here is my suggestion on this. This might be helpful.
You can make in two steps :
First Step (Data collection)
1) You can make a table which will contain the keywords and PostId (Here I am assuming each post will have a unique ID) along with other required fields.
2) For making keyword list you can parse each post and filter out Nouns, Verbs.
3) For each keyword and Postid will have a mapping in table.
Second Step (Data Extraction)
Now suppose you have to find the similar post of POST-1
1) First find the all keyword stored for POST-1. And store it in a data structure
2) Now take each keyword and find it in Table which do not belongs to POST-1. Now you will have a Data Structure of PostId for each keyword. Since one postid can come multiple times for a Keyword so here we can also introduce weight of each postid.
3) Now suppose you have 5 keyword for Post-1. Means you have 5 Data structure of Postid with their weight.
4) Now combine all Data Structures. During combination you will have to take care that if any PostId is coming more time means we are also increasing the weight.
5) Finally you will get the PostId which will have most weight. This will be close to your Post-1.
Hope it will make sense.

Pagination with XML and PHP?

before anyone asks; I've googled my 'question', I've also looks at the 'Questions that may already have your answer' and none of them work.
What I'm wanting to do is 'Pagination'. However, I don't want to use Databases as I've never had to and I'd rather not give up and go to them now as XML does everything I want it for.
The code I have is the following:
$files = glob('include/articles/*.xml');
foreach($files as $file){
$xml = new SimpleXMLElement($file, 0, true);
}
I've tried these ones already: XML pagination with PHP, PHP XML pagination and Pagination Filtered XML file and have achieved nothing. I have also tried a lot of Javascript 'pagination' scripts and still nothing.
So to sum it up: I have four articles (More to be added) and I want to show 2articles per a page. The following information will be 'pulled' from the xml file: ID, TITLE, CONTENT, PICTURE, AUTHOR, DATE by doing $xml->id and so on for the rest of them. Does anyone know of any way of doing this? as I've spent the past four hours (Its 4:04AM GMT) and have found nothing that works yet. (If I find anything that does work I'll make sure to update the question with the working code encase there is anyone else out there that needs help with this too.)
For a start define the order in which you want your articles to appear. I.e. which article goes on page 1, which one on page 2, etc. This is important, because that order will be the base for your pagination algorithm. Please note that glob() is not guaranteed to return results in any specific order, which means the order can change from one invocation of your script to another (notably when you add new articles) -- almost certainly not what you want.
Then the second step is to introduce another variable which is part of your URL that denotes the actual page (number) you're on. The URL query string would be a natural choice for putting this information, so your URL's look like: article.php?page=1. On the PHP side you can use the $_GET superglobal to retrieve the query string parameters.
Thirdly, use the new style URL's whenever you link to your article.php script. Additionally, validate the input --especially when you also want to display the current page based on this parameter (or you will end up with an injection vulnerability). This also means you want to have a default value (in case the value is invalid/wrong/ or not supplied at all for some reason).
Finally, filter your articles based on the two key pieces of information: the order of the articles w.r.t. the page number and the page number: i.e compute the actual articles that should appear on the current page.

I need to echo more columns from my Mysql

So far - and with great support from SO members, I am at the edge of finishing my Music Database program, along with all its complexities... As previously suggested, I am using Mysql, Php, JQuery and DataTable plugin, which gives great paginated results. All my Search results work as intended.
My database holds 15 columns of data. I have one table (OK for my current needs). I am able to currently POST and ECHO 12 columns of Search results within a 900px table.
To finalize my project, I also need to be able to show 3 more columns of - data which holds longer text (song description (150 Char), Producer Name(80 Char), and Publisher Name (80 Char), which obviously will not fit on this size table, even with wrapping - on the same row echo.
BUT how do I POST the last 3 columns in a SHOW/HIDE hidden div?, so users maybe click on a link and have these 3 pieces of information suddenly appear underneath any one row on the 900px table?
I have struggled for hundreds of hours just to get to this final stretch...So I need a final suggestion (or push off a cliff) as to where to look next for this answer...
Thank you in advance for any "easy" to understand suggestions you may have to offer me!!
Since you said that you are using datatable plugin, You can use following example to display lengthy details. Once you click on expand button, it will expand the particular row.
http://datatables.net/release-datatables/examples/api/row_details.html
Users don't need (and usually don't care) about all this information. Allow them to configure which columns they can see, and if they choose too many for the width then it's not your problem.
Create a link in your furthest right hand column (for example). Use an anchor link like this:
See More
In the next table row, put in a hidden <div id="extra-<?php echo $counter; ?>" class="hidden-more-data">..your data here..</div>
You can structure your data any way you like in those elements.
In CSS, you can hide .hidden-more-data with {display:none;}
Using jQuery, you can use $('.see-more').live('click',function(){}); in this kind of fashion:
$('.see-more').live('click',function(){
var href = this.href;
$(href).toggle();
return false;
});
And various similar possibilities.
use short headings and show full headings on mouse-over or title attribute.
Show limited char in table cells. And for detailed view show them in pop up div's or mouse-over events.

Categories